Array.slice()
Availability
Flash Player 5.
Usage
my_array.slice( [ start:Number [ , end:Number ] ] ) : Array
Parameters
A number specifying the index of the starting point for the slice. If
start
number, the starting point begins at the end of the array, where -1 is the last element.
A number specifying the index of the ending point for the slice. If you omit this parameter,
end
the slice includes all elements from the starting point to the end of the array. If
number, the ending point is specified from the end of the array, where -1 is the last element.
Returns
An array.
Description
Method; returns a new array that consists of a range of elements from the original array, without
modifying the original array. The returned array includes the
to, but not including, the
If you don't pass any parameters, a duplicate of
Example
The following example creates an array of five pets and uses
comprising only four-legged pets:
var myPets_array:Array = new Array("cat", "dog", "fish", "canary", "parrot");
var myFourLeggedPets_array:Array = new Array();
var myFourLeggedPets_array = myPets_array.slice(0, 2);
trace(myFourLeggedPets_array);
trace(myPets_array);
The following example creates an array of five pets, and then uses
parameter to copy the last two elements from the array:
var myPets_array:Array = new Array("cat", "dog", "fish", "canary", "parrot");
var myFlyingPets_array:Array = myPets_array.slice(-2);
trace(myFlyingPets_array); // traces canary,parrot
The following example creates an array of five pets and uses
parameter to copy the middle element from the array:
var myPets_array:Array = new Array("cat", "dog", "fish", "canary", "parrot");
var myAquaticPets_array:Array = myPets_array.slice(2,-2);
trace(myAquaticPets_array); // returns fish
element.
end
my_array
// returns cat,dog
// returns cat,dog,fish,canary,parrot
start
end
element and all elements up
start
is created.
to populate a new array
slice()
with a negative
slice()
with a negative
slice()
Array.slice()
is a negative
is a negative
start
end
113
Need help?
Do you have a question about the FLASH MX 2004-ACTIONSCRIPT LANGUAGE and is the answer not in the manual?