set(object, path, value) ⇒ Object | Array.<any>

Sets value for item selected by path

Returns: Object | Array.<any> - updated object Params

  • object Object | Array.<any> - object to update
  • path string | Array.<string> - path to be updated (array of items or dot-separated string can be provided)
  • value * - value to set in specified path

Description

import { set } from 'immutable-object-update';

const state = {
    a: {
        a1: 1,
        a2: 2
    },
    b: {
        b1: 3,
        b2: 4
    }
};

const updated = set(state, [ 'b', 'b1' ], 5);

// or

const updated = set(state, 'b.b1', 5);

As a result we will receive new object with structure below:

{
    a: {
        a1: 1,
        a2: 2
    },
    b: {
        b1: 3,
        b2: 5
    }
}

results matching ""

    No results matching ""