insert(object, path, value) ⇒ Object | Array.<any>
one of additional functions to work with array items
Returns: Object | Array.<any> - updated object
Params
- object
Object|Array.<any>- object to update - path
string|Array.<string>- path to be updated - value
any- value to be inserted
Description
import { insert } from 'immutable-object-update';
const state = {
a: {
b: [ 1, 2 ]
}
};
const updated = insert(state, [ 'a', 'b', 1 ], 3);
// or
const updated = insert(state, 'a.b.1', 3);
As a result we will receive new object with structure below:
{
a: {
b: [ 1, 3, 2 ]
}
}