User Guide

Array.splice() 121
Array.splice()
Availability
Flash Player 5.
Usage
my_array.splice(start:Number, deleteCount:Number [, value0:Object,
value1...valueN]) : Array
Parameters
start
An integer that specifies the index of the element in the array where the insertion or
deletion begins.
deleteCount An integer that specifies the number of elements to be deleted. This number
includes the element specified in the
start parameter. If no value is specified for deleteCount,
the method deletes all the values from the
start element to the last element in the array. If the
value is 0, no elements are deleted.
value An optional parameter that specifies the values to insert into the array at the insertion
point specified in the
start parameter.
Returns
The elements that were removed from the array.
Description
Method; adds and removes elements from an array. This method modifies the array without
making a copy.
Example
The following example creates an array and splices it using element index 1 for the start
parameter. This removes all elements from the array starting with the second element, leaving
only the element at index 0 in the original array:
var myPets_array:Array = new Array("cat", "dog", "bird", "fish");
trace( myPets_array.splice(1) ); // dog,bird,fish
trace( myPets_array ); // cat
The following example creates an array and splices it using element index 1 for the start
parameter and the number 2 for the
deleteCount parameter. This removes two elements from
the array, starting with the second element, leaving the first and last elements in the original array:
var myFlowers_array:Array = new Array("roses", "tulips", "lilies", "orchids");
trace( myFlowers_array.splice(1,2 ) ); // tulips,lilies
trace( myFlowers_array ); // roses,orchids