Immutable splice function for arrays and strings.

Usage no npm install needed!

<script type="module">
  import immutableSplice from '';



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.


splice(input, start)
splice(input, start, deleteCount)
splice(input, start, deleteCount, item1, item2, ...)


  • input the Array or String to splice.

  • start Number index at which to start changing the input.

  • deleteCount optional Number of elements in the array to remove from start.

    If deleteCount is omitted, then all the elements from start to the end of the input will be deleted.

  • item1, item2, ... optional elements to add to the input, beginning from start.

Return value

A new Array or String containing the changes made.


import splice from 'immutable-splice';

splice(['foo', 'bar', 'baz'], 1, 1);
// returns ['foo', 'baz']

splice('cool', 1, 2, '0', 'O');
// returns 'c0Ol'