Add items to the array:
The result of fruits will be:
The splice() method adds/removes items to/from an array, and returns the removed item(s).
Note: This method changes the original array.
![]()
The splice() method is supported in all major browsers.
| Parameter | Description |
|---|---|
| index | Required. An integer that specifies at what position to add/remove items, Use negative values to specify the position from the end of the array |
| howmany | Required. The number of items to be removed. If set to 0, no items will be removed |
| item1, ..., itemX | Optional. The new item(s) to be added to the array |
| Type | Description |
|---|---|
| Array | A new array containing the removed items, if any |
| JavaScript Version: | 1.2 |
|---|
At position 2, add the new items, and remove 1 item:
The result of fruits will be:
At position 2, remove 2 items:
The result of fruits will be:
JavaScript Array Object
Your message has been sent to W3Schools.