in ES6 there is a new way to copy objects so you can have a nice way to handle inmutable states:
let oldObj = { foo: 1}; // { foo: 1 }
let newObj = { ...oldObj, bar: 2 }; // { foo: 1, bar: 2}
However what I want to achieve is:
let oldObj = { foo: [1] }; // { foo: [1] }
let newObj = ??? // { foo: [1, 2] }
Any idea on how to achieve this?
{ ...oldObj, foo: [...oldObj.foo, 2] }--- no easy way here. PS: the syntax you're referring to is not "ES6" and is not even standardised yet.