请教下,AS3 操作数组时,能否根据数组的索引来删除某条数组元素呢?怎么写的呢?谢谢!!

请教下,AS3 操作数组时,能否根据数组的索引来删除某条数组元素呢?怎么写的呢?谢谢!!

var vegetables:Array =
new Array(
"spinach", //索引0
"green pepper", 1
"cilantro", 2
"onion", 3
"avocado"); 4

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

用数组对象的splice属性,可以看看API文档,
splice(startIndex:int, deleteCount:uint, ... values):Array
第一个参数你开始删除的索引值,第二个参数是删除几个,第三个参数是你要插入的列表或数组对象,用逗号分开。
温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-08-05
array.splice(index, 1);
index是要开始删除元素的起始位置,后边是删除长度
第2个回答  2012-08-05
array.splice
这种问题直接查API 没必要来问