Immutable Data Patterns
Copying Objects
Build a new object from existing fields.
Copying Objects
copy_object.js
const quantity = 3;
const copied = JSON.stringify({
...{ item: "book" },
quantity: quantity,
});
const label = "quantity=" + quantity;
console.log("copied=" + copied);
console.log("label=" + label);
copy-object
Object spread copies fields into a new object. Later fields can add new values without mutating the original shape.