Name

Array.splice( ) Method — remove elements from, and/or add elements to, an array

Availability

Flash 5

Synopsis

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 non-negative integer representing the number of elements to remove from array, including the element at startIndex. If 0, no elements are deleted. If 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.

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 moves elements up or down 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 insert the elements "x", "y", and "z" in their place. // This ...

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.