Array.slice( ) Method | Flash 5 |
create a new array using a subset of elements from an existing array |
A zero-relative integer specifying the first element of array to add to the new array. If negative, startIndex indicates an element number counting backward from the end of array (-1 is the last element, -2 is the second-to-last element, etc.).
An integer specifying the element after the last element of array to add to the new array. If negative, endIndex counts backward from the end of array (-1 is the last element, -2 is the second-to-last element, etc.). If omitted, endIndex defaults to array.length.
A new array containing the elements of array from startIndex to endIndex-1.
The slice( ) method creates a new array by extracting a series of elements from an existing array. The original array is not modified. The new array is a subset of the elements of the original array, starting with array[startIndex] and ending with array[endIndex - 1].
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);
Array.splice( ); "The slice( ) Method," in Chapter 11; "The delete Operator," in Chapter 5