JavaScript Array splice()
Example
Add elements to an array:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
// At position 2, add 2 elements:
fruits.splice(2, 0, "Lemon", "Kiwi");
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The splice() method adds and/or removes array elements.
splice() overwrites the original array.
Browser Support
splice() is fully supported in all browsers:
| Chrome | IE | Edge | Firefox | Safari | Opera |
| Yes | Yes | Yes | Yes | Yes | Yes |
Syntax
array.splice(index, howmany, item1, ....., itemX)
Parameter Values
| Parameter | Description |
|---|---|
| index | Required. The position to add/remove items. Negative values a the position from the end of the array. |
| howmany | Optional. Number of items to be removed. |
| item1, ..., itemX | Optional. New elements(s) to be added |
Technical Details
| Return Value: | An empty Array, or an Array containing removed items (if any). |
|---|---|
| JavaScript Version: | ECMAScript 1 |
More Examples
Example
At position 2, add the new items, and remove 1 item:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 1, "Lemon", "Kiwi");
Try it Yourself »
Example
At position 2, remove 2 items:
const fruits = ["Banana", "Orange", "Apple", "Mango", "Kiwi"];
fruits.splice(2, 2);
Try it Yourself »

