Array

Array.prototype.toSpliced

Returns a new array with some elements removed and/or replaced at a given index, without modifying the original array

Syntax

JavaScript
array.toSpliced(start, deleteCount?, ...items)

Parameters

ParameterTypeDescription
startnumberZero-based index at which to start changing
deleteCountnumberNumber of elements to remove
itemsT[]Elements to insert at start

Return Value

A new array with the specified changes applied

Examples

Basic Usage
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)
Practical Example
const months = ['Jan', 'Mar', 'Apr'];
const fixed = months.toSpliced(1, 0, 'Feb');
console.log(fixed); // ['Jan', 'Feb', 'Mar', 'Apr']
Advanced Usage
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

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.