immutable-splice
Changes the contents of an array or string by removing or replacing existing elements and/or adding new elements.
Based off the Array.prototype.splice()
method—but immutable.
Usage
splice(input, start)
splice(input, start, deleteCount)
splice(input, start, deleteCount, item1, item2, ...)
Parameters
-
input
theArray
orString
to splice. -
start
Number
index at which to start changing theinput
. -
deleteCount
optionalNumber
of elements in the array to remove fromstart
.If
deleteCount
is omitted, then all the elements fromstart
to the end of theinput
will be deleted. -
item1, item2, ...
optional elements to add to theinput
, beginning fromstart
.
Return value
A new Array
or String
containing the changes made.
Examples
import splice from 'immutable-splice';
splice(['foo', 'bar', 'baz'], 1, 1);
// returns ['foo', 'baz']
splice('cool', 1, 2, '0', 'O');
// returns 'c0Ol'