Array.splice( ) Method

ActionScript for Flash MX: The Definitive Guide, 2nd Edition
By Colin Moock
Chapter 18.  ActionScript Language Reference
Array.splice( ) Method Flash 5

remove elements from, and/or add elements to, an array
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, startIndex specifies an element counting back from the end of array (-1 is the last element, -2 is the second-to-last element, etc.).

deleteCount

An optional, nonnegative integer representing the number of elements to remove from array, including the element at startIndex. If deleteCount is 0, no elements are deleted. If deleteCount is omitted, all elements from startIndex to the end of the array are removed.

value1, ...valuen

An optional list of one or more values to be added to array at index startIndex after the specified elements have been deleted. If this list is omitted, no elements are added.

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 compacts deleted elements and moves remaining elements as needed 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 inserts the elements "x", "y", and "z" in their place. // This changes myList to [1, "x", "y", "z", 4, 5]. myList.splice(1, 2, "x", "y", "z");

See Also

Array.slice( ); "The splice( ) Method," in Chapter 11

     



    ActionScript for Flash MX. The Definitive Guide
    ActionScript for Flash MX: The Definitive Guide, Second Edition
    ISBN: 059600396X
    EAN: 2147483647
    Year: 2002
    Pages: 780
    Authors: Colin Moock

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net