immutable-array-insert

0.2.6 • Public • Published

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

  1. the original array
  2. 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

  1. Check out the issues
  2. Fork this repository
  3. Clone your fork
  4. Check out a feature branch ($ git checkout -b my-feature)
  5. Make your changes and push your branch to your GitHub repo
  6. Create a pull request from your branch to this repo's master branch
  7. When all is merged, pull down the upstream changes to your master
  8. Delete your feature branch

Readme

Keywords

Package Sidebar

Install

npm i immutable-array-insert

Weekly Downloads

0

Version

0.2.6

License

MIT

Last publish

Collaborators

  • rpearce