0.1.3 • Published 8 years ago

array-add-item v0.1.3

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

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