splice
Immutable splice.
Installation
$ npm install @f/splice
Usage
var splice = require('@f/splice')
splice([1, 2, 3], 1, 1) // -> [1, 3]
splice([1, 2, 3], 1, 1, 5), // -> [1, 5, 3]
splice([1, 2, 3], 0, 1, 5), // -> [5, 2, 3]
API
splice(arr, idx, deleteCount, ...items)
-
arr
- The array you want to splice -
idx
- The position in the array to begin removing/inserting items -
deleteCount
- The number of items to remove at positionidx
-
...items
- Optional list of items to insert at positionidx
Returns: A new array with the desired changes.
License
MIT