immutable-array-insert
v0.2.6
Published
Easily insert items in an array without mutating the original array.
Downloads
12
Readme
immutable-array-insert
Easily insert items in an array without mutating the original array.
Installation
$ npm install --save immutable-array-insert
Usage
const insert = require('immutable-array-insert')
const arr = [1, 2, 3, 4, 5, 6]
const newArr = insert(arr, 2, 'ABC', { name: 'Hello' })
console.log(newArr)
// => [1, 2, 'ABC', Object, 3, 4, 5, 6]
The first 2 arguments are
- the original array
- the index at which to insert the items
and the rest of the parameters are variadic, allowing you to pass as my items as arguments as you'd like.
insert(array, index, items)
Insert an item in an array without mutating the original array.
Parameters
array: array
, The source array.
index: number
, The index at which you'd like to insert.
items: *
, Additional arguments: the items to be inserted at the index.
Contribute
- Check out the issues
- Fork this repository
- Clone your fork
- Check out a feature branch (
$ git checkout -b my-feature
) - Make your changes and push your branch to your GitHub repo
- Create a pull request from your branch to this repo's master branch
- When all is merged, pull down the upstream changes to your master
- Delete your feature branch