update an item of an array
Just a simple function to update an item of an Array. Works well in both, the browser & node.
install
npm i -S array-update-item
and use it
import updateItemInArray from 'array-update-item'
const updateItemInArray = require('array-update-item')
const abcde = updateItemInArray(['a', 'b', 'b', 'd'], 'c', 2)
console.log(abcde)
behavior
updateItemInArray
is a pure function, it does not mutate the provided array.- the item is not updated if:
- the index is out of the range of the array (grater than
arr.length
or less than 0) - the index is not a number or is a float number.
FAQ