Update an item of an array

Usage no npm install needed!

<script type="module">
  import arrayUpdateItem from '';


update an item of an array

XO code style

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


npm i -S array-update-item

and use it

import updateItemInArray from 'array-update-item'
// OR
const updateItemInArray = require('array-update-item')

const abcde = updateItemInArray(['a', 'b', 'b', 'd'], 'c', 2)
console.log(abcde) // ['a', 'b', 'c', 'd']


  • 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.