When working with ES6, there is a convenient new method for copying objects which helps in handling immutable states:
let oldObj = { foo: 1}; // { foo: 1 }
let newObj = { ...oldObj, bar: 2 }; // { foo: 1, bar: 2}
But what if I want to accomplish the following:
let oldObj = { foo: [1] }; // { foo: [1] }
let newObj = ??? // { foo: [1, 2] }
Does anyone know how this can be achieved?