Looking for javascript Answers? Try Ask4KnowledgeBase
Looking for javascript Keywords? Try Ask4Keywords

JavaScript Object rest/spread (...)


Example

7

Object spreading is just syntactic sugar for Object.assign({}, obj1, ..., objn);

It is done with the ... operator:

let obj = { a: 1 };

let obj2 = { ...obj, b: 2, c: 3 };

console.log(obj2); // { a: 1, b: 2, c: 3 };

As Object.assign it does shallow merging, not deep merging.

let obj3 = { ...obj, b: { c: 2 } };

console.log(obj3); // { a: 1, b: { c: 2 } };

NOTE: This specification is currently in stage 3