Suppose there is an object:
const object = { 'foo': { 'bar': [1, 2, 3] } }
I need to push 4 into the object.foo.bar array.
Now I am doing this:
const initialState = Immutable.fromJS(object) const newState = initialState.setIn( ['foo', 'bar', object.foo.bar.length], 4 ) console.log(newState.toJS())
But I do not really like this, since I need to use object.foo.bar.length in the path. In my real example, the object is nested much deeper, and the length of the array looks very ugly. Is there any other, more convenient way?
Alexandr Lazarev
source share