Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The splice() method of Array instances changes the contents of an array by removing or replacing existing elements and/or adding new elements in place.
To create a new array with a segment removed and/or replaced without mutating the original array, use toSpliced(). To access part of an array without modifying it, see slice().
Zero-based index at which to start changing the array, converted to an integer.
An integer indicating the number of elements in the array to remove from start.
If deleteCount is omitted, or if its value is greater than or equal to the number of elements after the position specified by start, then all the elements from start to the end of the array will be deleted. However, if you wish to pass any itemN parameter, you should pass Infinity as deleteCount to delete all elements after start, because an explicit undefined gets converted to 0.
If deleteCount is 0 or negative, no elements are removed. In this case, you should specify at least one new element (see below).
item1, …, itemN OptionalThe elements to add to the array, beginning from start.
If you do not specify any elements, splice() will only remove elements from the array.
An array containing the deleted elements.
If only one element is removed, an array of one element is returned.
If no elements are removed, an empty array is returned.
The splice() method is a mutating method. It may change the content of this. If the specified number of elements to insert differs from the number of elements being removed, the array's length will be changed as well. At the same time, it uses [Symbol.species] to create a new array instance to be returned.
If the deleted portion is sparse, the array returned by splice() is sparse as well, with those corresponding indices being empty slots.
The splice() method is generic. It only expects the this value to have a length property and integer-keyed properties. Although strings are also array-like, this method is not suitable to be applied on them, as strings are immutable.
splice(0, 0, ...elements) inserts elements at the start of the array like unshift().
splice(array.length, 0, ...elements) inserts elements at the end of the array like push().
The splice() method preserves the array's sparseness.
The splice() method reads the length property of this. It then updates the integer-keyed properties and the length property as needed.
| ECMAScript® 2027 Language Specification # sec-array.prototype.splice |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.