JavaScript Array.prototype.toSpliced() Method
The toSpliced() method returns a copy of an array with elements removed, replaced or inserted, leaving the original unchanged.
Description
The toSpliced() method is the copying version of splice(). Instead of changing the array and returning the removed elements, it returns a new array with the change made, and the original stays as it was.
It takes the same arguments as splice(): a start index (negative values count from the end), the number of elements to remove, and any elements to insert. Unlike splice(), it doesn't tell you which elements were removed; if you need them, use slice() on the original.
It's useful for immutable updates, such as removing an item from a list in framework state: items.toSpliced(index, 1). The result is never sparse, as empty slots become undefined, and like the other copying methods it makes a shallow copy.
Syntax
array.toSpliced(start, deleteCount, item1, item2, ...)Parameters
- startThe index to start at.
- deleteCountOptional. How many elements to remove.
- item1, item2, ...Optional. Elements to insert.
Return Value
A new array with the changes applied.
Example
Browser Support
The following information will show you the current browser support for the Array.prototype.toSpliced() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





