Typed Array with()
JavaScript Array with() Method
ES2023 added the Array with() method as a safe way to update elements in an array without altering the original array.
Example
// Create a Typed Array
const myArr = Int16Array.from([10,15,20,25,30]);
// Create a new Array
const newArr = myArr.with(2, 10);
Try it Yourself »
Description
The with() method updates a specified array element.
The with() method returns a new array.
The with() method does not change the original array.
Syntax
typed-array.with(index, value)
Parameters
| Parameter | Description |
| index | Required. The index (position) of the item to change. A negative index counts from the end of the array. |
| value | Required. The new value. |
Return Value
| Parameter | Description |
| Typed Array | A new typed array containing with one element changed. |
JavaScript Typed Arrays
Browser Support
typed-array.with() is a JavaScript 2023 feature.
ES 2023 is supported in all modern browsers since July 2023:
| Chrome 110 |
Edge 110 |
Firefox 115 |
Safari 16.4 |
Opera 96 |
| Feb 2023 | Feb 2023 | Jul 2023 | Mar 2023 | May 2023 |
❮ Reference ❯