1.0.1 • Published 4 years ago
immutable-splice v1.0.1
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
inputtheArrayorStringto splice.startNumberindex at which to start changing theinput.deleteCountoptionalNumberof elements in the array to remove fromstart.If
deleteCountis omitted, then all the elements fromstartto the end of theinputwill 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'