Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Easily insert items in an array without mutating the original array.

License

Notifications You must be signed in to change notification settings

rpearce/immutable-array-insert

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Easily insert items in an array without mutating the original array.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages