seantrant
8/30/2018 - 10:01 AM

Copy object or arrays with spread operator

Prefer the object spread operator over Object.assign to shallow-copy objects. Use the object rest operator to get a new object with certain properties omitted.

For deep copies we can use the json.pares(json.stringify(whatever)) method. This will not copy over functions stored in the object correctly however

// good
const original = { a: 1, b: 2 };
const copy = { ...original, c: 3 }; // copy => { a: 1, b: 2, c: 3 }