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

ParameterDescription
start Index to start changing.
deleteCount optional How many elements to remove.
items optional Elements to insert.

Return value

A new array.

Examples

Insert into a copyTry it yourself
const months = ["Jan", "Mar"];
console.log(months.toSpliced(1, 0, "Feb"), months);

Output

[ 'Jan', 'Feb', 'Mar' ] [ 'Jan', 'Mar' ]
Remove from a copyTry it yourself
const ids = [1, 2, 3, 4];
console.log(ids.toSpliced(1, 2));

Output

[ 1, 4 ]

Version history

VersionChange
JavaScript ES2023Added