JavaScript array.with() Function

JavaScript Logo

array.with() – ES2023: Returns a new array with the element at the given index replaced by the provided value (non-mutating).

๐Ÿ‘‰ Syntax

newArray = array.with(index, value);

๐Ÿงช Example

const arr=[1,2,3]; const updated=arr.with(1, 99); // [1,99,3]

Comments