From http://www.w3schools.com (Copyright Refsnes Data)
JavaScript Array Object
The splice() method is used to remove and add new elements to an array.
| arrayObject.splice(index,howmany,element1,.....,elementX) |
| Parameter | Description |
|---|---|
| index | Required. Specify where to add/remove elements. Must be a number |
| howmany | Required Specify how many elements should be removed. Must be a number, but can be "0" |
| element1 | Optional. Specify a new element to add to the array |
| elementX | Optional. Several elements can be added |
Example 1Add an element to an array:
The output of the code above will be:
Try it yourself » |
Example 2Remove the element at index 2 ("Stale"), and add a new element ("Tove") here (at index 2):
The output of the code above will be:
Try it yourself » |
Example 3Remove three elements, starting at index 2, and add a new element ("Tove") there instead:
The output of the code above will be:
Try it yourself » |
JavaScript Array Object
From http://www.w3schools.com (Copyright Refsnes Data)