add item in array
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'
const addItemInArray = require('array-add-item')
const abcde = addItemInArray(['a', 'c', 'd', 'e'], 'b', 1)
console.log(abcde)
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