shiftN(object, path, n) ⇒ 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
  • n number - number of elements to remove

Description

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

const state = {
    a: {
        b: [ 1, 2, 3 ]
    }
};

const updated = shiftN(state, [ 'a', 'b' ], 2);

// or

const updated = shiftN(state, 'a.b', 2);

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

{
    a: {
        b: [ 3 ]
    }
}

Please note: shiftN() function won't return removed items

results matching ""

    No results matching ""