Standard built-ins
Array.prototype.with()
Returns a shallow copy with one position replaced. Negative indices count from the end; out-of-range indices throw RangeError. Ordinary holes in the other positions become undefined.
Formal Syntax & Structure
javascript syntaxjavascript
array.with(index, value)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| index | number | Relative index, converted to an integer. |
| value | any | Replacement value. |
Return Value
Array
New array of the same length.
Working Example
Example Snippetjavascript
console.log([1,2,3].with(-1,7).join(","));