next up previous contents
Next: unshift Up: Methods Previous: sort   Contents


splice

Description

Adds and removes elements from an array. This method modifies the array without making a copy. The elements deleted by this method are put into a new array as the return.


Syntax

array1.splice(start, deleteCount, value_0, value_1, ..., value_N)


Parameters

start
The index of the element in the array where the insertion or deletion begins.
deleteCount
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 of the values from the start element to the last element in the array. If the value is 0, no elements are deleted.
value_0, value_1, ..., value_N
Zero or more values to insert into the array at the insertion point specified in the start parameter. This parameter is optional.


Returns

An array contains all deleted elements


Example

data = new Array();
for (i = 0; i < 10; i++) data[i] = "data" + i;
trace(data.splice(2, 7, "data2", "data3"));
//output:'data2,data3,data4,data5,data6,data7,data8
trace(data);
//output: data0,data1,data2,data3,data9




Copyright ©2000-2010 Shanghai TopCMM Software Technologies. All Rights Reserved.