1.0.1 • Published 3 years ago

immutable-splice v1.0.1

Weekly downloads
2
License
MIT
Repository
github
Last release
3 years ago

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 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.

Examples

import splice from 'immutable-splice';

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

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