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

set() and update() operations can help with new values, but it requires to many steps to remove items. Here remove() operation comes.

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

  • object Object | Array.<any> - object to update
  • path string | Array.<string> - path to item to be removed (array of items or dot-separated string can be provided)

Description

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

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

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

// or

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

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

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

Please note: remove() function won't return removed item

results matching ""

    No results matching ""