Object Manipulation
Merging
Object.assign- mutates left-hand-side
- since
ES5 - iterates
enumerableown properties
...- creates new object
- since
ES9 - iterates
enumerableown properties
js
let original = { a: 1, b: 2 };
// mutates original
let objectClone = Object.assign(original, { foo: 'foo' });
// or create new object
let objectClone = Object.assign({}, original, { foo: 'foo' });
// spread operator always create new object
let objectClone = { ...object };1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10