array-add-item

0.1.3 • Public • Published

add item in array

XO code style

Just a simple function to add an item into an Array. Works well in both, the browser & node.

install

npm i -S array-add-item

and use it

import addItemInArray from 'array-add-item'
// OR
const addItemInArray = require('array-add-item')
 
const abcde = addItemInArray(['a', 'c', 'd', 'e'], 'b', 1)
console.log(abcde) // ['a', 'b', 'c', 'd', 'e']

behavior

  • addItemInArray is a pure function, it does not mutate the provided array.
  • item is added at the end if no position is provided or it is out of the range of the array (grater than arr.length or less than 0).
  • returns the array if the position provided is not a number or is a float number.

FAQ

Readme

Keywords

Package Sidebar

Install

npm i array-add-item

Weekly Downloads

1

Version

0.1.3

License

MIT

Last publish

Collaborators

  • gillchristian