Favorites

JavaScript Array.prototype.splice() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Array.prototype.splice()
JavaScript Array Instance methodThis method is supported by all modern browsers.
Updated 28th November 2026

The splice() method changes an array in place by removing, replacing or inserting elements at a given position.

Description

The splice() method changes the contents of an array in place: it can remove elements, insert new ones, or both at once. It returns an array of whatever was removed.

arr.splice(i, 1) removes one element at index i, and arr.splice(i, 0, x) inserts x there without removing anything. Because it mutates the array, use toSpliced() when you need an unchanged original.

A negative start counts from the end, so arr.splice(-1, 1) removes the last element. If deleteCount is left out, everything from start onwards is removed, which is a quick way to truncate an array. Because it shifts the following elements, using splice() inside a forward loop can skip items; loop backwards when removing several.

Syntax

array.splice(start)
array.splice(start, deleteCount)
array.splice(start, deleteCount, item1, item2, ...)

Parameters

  • startThe index to start changing the array at. Negative values count from the end.
  • deleteCountOptional. How many elements to remove. If left out, everything from start to the end is removed.
  • item1, item2, ...Optional. Elements to insert at start.

Return Value

An array of the removed elements (empty if none were removed).

Example

const months = ['Jan', 'Mar', 'Apr', 'Jun'];
months.splice(1, 0, 'Feb');            // insert
console.log(months);

const removed = months.splice(3, 1, 'May');   // replace
console.log(removed, months);

Browser Support

The following information will show you the current browser support for the Array.prototype.splice() method. Hover over a browser icon to see the version that first introduced support for this method.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee