Closed ir3ne closed 5 hours ago
A shallow copy is a duplicate of an object where the top-level properties are copied, but the nested objects or arrays are shared between the original and the copy. This means that if you modify a nested object in the copy, the change will also affect the original object, since both reference the same nested object.
In JavaScript, you can create a shallow copy of an object using several methods. Here are a few common techniques:
Object.assign()
const original = {
name: "Alice",
age: 25,
address: {
city: "Wonderland",
zip: "12345"
}
};
const shallowCopy = Object.assign({}, original);
shallowCopy.address.city = "New City";
console.log(original.address.city);
hey @TBalo thanks for this contribution? would you like to open a PR for this?
hey @TBalo thanks for this contribution? would you like to open a PR for this?
You're welcome @ir3ne.
Yeah sure..
You could assign it.
See if add shallow copy of ..an object, etc