actionscript数组删除元素

时间:2010-03-28 03:42:51

标签: actionscript-3

我有一个包含10个元素的数组项。我需要删除第5个元素(index = 4) 新数组应该有9个元素,第5个元素之后的所有元素都将向前移动

我应该使用哪些命令?

1 个答案:

答案 0 :(得分:2)

Splice

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#splice%28%29

var vegetables:Array = new Array("spinach",
             "green pepper",
             "cilantro",
             "onion",
             "avocado");

var spliced:Array = vegetables.splice(2, 2);
trace(vegetables); // spinach,green pepper,avocado
trace(spliced);    // cilantro,onion

vegetables.splice(1, 0, spliced);
trace(vegetables); // spinach,cilantro,onion,green pepper,avocado