Name
Array.splice( ) Method — remove elements from, and/or add elements to, an array
Availability
Flash 5
Synopsis
array.splice(startIndex) array.splice(startIndex, deleteCount) array.splice(startIndex, deleteCount, value1,...valuen)
Arguments
- startIndex
The zero-relative element index at which to start element deletion and optional insertion of new elements. If negative,
startIndexspecifies an element counting back from the end ofarray(-1 is the last element, -2 is the second-to-last element, etc.).
- deleteCount
An optional non-negative integer representing the number of elements to remove from
array, including the element atstartIndex. If 0, no elements are deleted. If omitted, all elements fromstartIndexto the end of the array are removed.
- value1,...value
n An optional list of one or more values to be added to
arrayat indexstartIndexafter the specified elements have been deleted.
Returns
A new array containing the deleted elements (the
original array is modified separately to
reflect the requested changes).
Description
The splice( ) method removes the elements from
array
[
startIndex
]
to
array
[
startIndex
+
deleteCount
-1] and then
optionally inserts new elements starting at
startIndex. The splice(
) method does not leaves gaps in
array ; it moves elements up or down to
ensure the contiguity of elements in the array.
Example
myList = new Array (1, 2, 3, 4, 5); // Deletes the second and third elements from the list // and insert the elements "x", "y", and "z" in their place. // This ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access