Array

Array.prototype.splice

Changes the contents of an array by removing or replacing existing elements and/or adding new elements in place

Syntax

JavaScript
array.splice(start, deleteCount?, ...items)

Parameters

ParameterTypeDescription
startnumberZero-based index at which to start changing the array
deleteCountnumberNumber of elements to remove from start
itemsT[]Elements to add to the array, beginning from start

Return Value

An array containing the deleted elements

Examples

Basic Usage
const months = ['Jan', 'Mar', 'Apr'];
months.splice(1, 0, 'Feb');
console.log(months); // ['Jan', 'Feb', 'Mar', 'Apr']
Practical Example
const arr = [1, 2, 3, 4, 5];
const removed = arr.splice(1, 2);
console.log(removed); // [2, 3]
console.log(arr); // [1, 4, 5]
Advanced Usage
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

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.