JavaScript (ES2026) reference · Array Methods

JavaScript Array splice() Method

Remove, replace or insert elements at a position, changing the array in place. Returns the removed elements.

JavaScript (ES2026) Since ES3

Syntax

array.splice(start, deleteCount, item1, /* …, */ itemN)

Parameters

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

Return value

An array of the removed elements.

Examples

InsertTry it yourself
const months = ["Jan", "Mar", "Apr"];
months.splice(1, 0, "Feb"); // insert
console.log(months);

Output

[ 'Jan', 'Feb', 'Mar', 'Apr' ]
RemoveTry it yourself
const nums = [1, 2, 3, 4, 5];
const removed = nums.splice(1, 2); // remove two
console.log(removed, nums);

Output

[ 2, 3 ] [ 1, 4, 5 ]
ReplaceTry it yourself
const colors = ["red", "green", "blue"];
colors.splice(1, 1, "yellow", "purple"); // replace one with two
console.log(colors);

Output

[ 'red', 'yellow', 'purple', 'blue' ]

Version history

VersionChange
JavaScript ES3Added