JavaScript Array method: splice()
[this page | pdf | back links]
The splice() method (when applied to a JavaScript
array) adds
/ removes elements to / from the array.
It
has the following syntax with the following parameters. It returns a new
array containing the removed items, if any.
array.splice(index, numberremoved, item1,
item2, …)
|
Parameter
|
Required / Optional
|
Description
|
|
index
|
Required
|
Integer specifying
position at which to add/remove items. Negative numbers specify from end of
array
|
|
numberremoved
|
Optional
|
Number of items to be
removed (if set to zero then no items will be removed)
|
|
item1, item2, …
|
Optional
|
New item(s) to be added
to the array
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Arrays