JavaScript Array with() method
updates elements in an array without altering the original array

with() method updates elements in an array without altering the original array.

syntax

with(index, value)

index The index (position) of the item to change.

value The new value.

The first position is 0, the second is 1, ...

Negative index counts back from the end of the array.

with() method returns a new array with the element at the given index replaced with the given value.

with() method does not change the original array.

RangeError thrown if index is not found.

syntax description
update element at specified index in myArray with specified value
myArray.with(index, value)