JavaScript (ES2026) reference · Array Methods
JavaScript Array toSpliced() Method
Return a new array with elements removed, replaced or inserted at a position, leaving the original unchanged.
JavaScript (ES2026) Since ES2023
Syntax
array.toSpliced(start, deleteCount, item1, /* …, */ itemN)
Parameters
| Parameter | Description |
|---|---|
start |
Index to start changing. |
deleteCount optional |
How many elements to remove. |
items optional |
Elements to insert. |
Return value
A new array.
Examples
const months = ["Jan", "Mar"];
console.log(months.toSpliced(1, 0, "Feb"), months);
Output
[ 'Jan', 'Feb', 'Mar' ] [ 'Jan', 'Mar' ]
const ids = [1, 2, 3, 4];
console.log(ids.toSpliced(1, 2));
Output
[ 1, 4 ]
Version history
| Version | Change |
|---|---|
| JavaScript ES2023 | Added |
Related
array.splice()· Remove, replace or insert elements at a position, changing the array in place. Returns the removed elements.array.slice()· Return a shallow copy of part of the array, from start up to (not including) end. The original is not changed.array.with()· Return a copy of the array with one element replaced, leaving the original unchanged. Negative indexes count from the end.- JavaScript Arrays · tutorial
- JavaScript Array Methods · tutorial