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
// ORconst addItemInArray = const abcde = console // ['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
- Why such small module?: Sindre gives a good answer to this.