Name
Array.slice( ) Method — create a new array using a subset of elements from an existing array
Availability
Flash 5
Synopsis
array.slice(startIndex, endIndex)
Arguments
- startIndex
A zero-relative integer specifying the first element in
array
to add to the new array. If negative,startIndex
indicates an element number counting backward from the end ofarray
(-1 is the last element, -2 is the second-to-last element, etc.).
- endIndex
An integer specifying the element after the last element in
array
to add to the new array. If negative,endIndex
counts backward from the end ofarray
(-1 is the last element, -2 is the second-to-last element, etc.). If omitted,endIndex
defaults toarray
.length
.
Returns
A new array containing the elements of
array
from
startIndex
to
endIndex
-1
.
Description
The slice( )
method creates a new array by
extracting a series of elements from an existing array. The new array
is a subset of the elements of the original
array
, starting with
array
[
startIndex
]
and ending with
array
[
endIndex
-1]
.
Example
myList = new Array("a", "b", "c", "d", "e"); // Set myOtherList to ["b", "c", "d"] myOtherList = myList.slice(1, 4); // Set anotherList to ["d", "e"] anotherList = myList.slice(3); // Set yetAnotherList to ["c", "d"] yetAnotherList = myList.slice(-3, -1);
See Also
Array.splice( )
; Section 11.9.3 in Chapter 11, Section 5.11.4 in Chapter 5
Get ActionScript: The Definitive Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.