Array.prototype.splice
Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place
Syntax
array.splice(start, deleteCount?, ...items)Parameters
| Parameter | Type | Description |
|---|---|---|
| start | number | Zero-based index at which to start changing the array |
| deleteCount | number | Number of elements to remove from start |
| items | T[] | Elements to add to the array, beginning from start |
Return Value
An array containing the deleted elements
Examples
const months = ['Jan', 'Mar', 'Apr'];
months.splice(1, 0, 'Feb');
console.log(months); // ['Jan', 'Feb', 'Mar', 'Apr']const arr = [1, 2, 3, 4, 5];
const removed = arr.splice(1, 2);
console.log(removed); // [2, 3]
console.log(arr); // [1, 4, 5]const colors = ['red', 'green', 'blue'];
colors.splice(1, 1, 'yellow', 'orange');
console.log(colors); // ['red', 'yellow', 'orange', 'blue']Understanding Array.prototype.splice
The Array.prototype.splice method in JavaScript changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. 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.splice(start, deleteCount?, ...items). It accepts 3 parameters: start, deleteCount, items. When called, it returns an array containing the deleted elements. Understanding when and how to use splice() helps you write more expressive, readable code.
Common use cases for Array.prototype.splice include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like array-tospliced, array-slice, array-concat, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Array.prototype.splice is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Array.prototype.toSplicedReturns a new array with some elements removed and/or replaced at a given index, without modifying the original array
Array.prototype.sliceReturns a shallow copy of a portion of an array into a new array object selected from start to end (end not included)
Array.prototype.concatMerges two or more arrays into a new array without changing the existing arrays
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.