Array.prototype.toSpliced
Returns a new array with some elements removed and/or replaced at a given index, without modifying the original array
Syntax
array.toSpliced(start, deleteCount?, ...items)Parameters
| Parameter | Type | Description |
|---|---|---|
| start | number | Zero-based index at which to start changing |
| deleteCount | number | Number of elements to remove |
| items | T[] | Elements to insert at start |
Return Value
A new array with the specified changes applied
Examples
const arr = [1, 2, 3, 4, 5];
const result = arr.toSpliced(1, 2);
console.log(result); // [1, 4, 5]
console.log(arr); // [1, 2, 3, 4, 5] (unchanged)const months = ['Jan', 'Mar', 'Apr'];
const fixed = months.toSpliced(1, 0, 'Feb');
console.log(fixed); // ['Jan', 'Feb', 'Mar', 'Apr']const colors = ['red', 'green', 'blue'];
const updated = colors.toSpliced(1, 1, 'yellow');
console.log(updated); // ['red', 'yellow', 'blue']Understanding Array.prototype.toSpliced
The Array.prototype.toSpliced method in JavaScript returns a new array with some elements removed and/or replaced at a given index, without modifying the original array. It belongs to the Array object and is one of the most widely used methods for working with array values in modern JavaScript and TypeScript applications.
The method signature is array.toSpliced(start, deleteCount?, ...items). It accepts 3 parameters: start, deleteCount, items. When called, it returns a new array with the specified changes applied. Understanding when and how to use toSpliced() helps you write more expressive, readable code.
Common use cases for Array.prototype.toSpliced include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-splice, array-tosorted, array-toreversed, enabling you to chain operations together for complex data manipulation pipelines.
Supported in Chrome 110+, Firefox 115+, Safari 16+, Edge 110+, and Node.js 20+.
Browser Compatibility
Supported in Chrome 110+, Firefox 115+, Safari 16+, Edge 110+, and Node.js 20+.
Related Methods
Array.prototype.spliceChanges the contents of an array by removing or replacing existing elements and/or adding new elements in place
Array.prototype.toSortedReturns a new array with the elements sorted in ascending order, without modifying the original array
Array.prototype.toReversedReturns a new array with the elements in reversed order, without modifying the original array
Array.prototype.withReturns a new array with the element at the given index replaced with the given value, without modifying the original array
More Array Methods
Other methods in the Array object
Related Tools
More Array Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.