我有一个数组猫,狗,鹦鹉
和希望通过索引中删除该项目。
目前,我有
函数removeit(myindex){
动物[myindex] = animals.pop()
}
解决方案
您想拼接
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice%28%29
Array.splice(起点,删除数);
VAR newArray:阵列= myArray.splice(2,1); //这将删除一切是在索引2并返回一个新的数组。
更改功能
函数removeit(myindex){
animals.splice(myindex,1);
}
I have an array 'cat', 'dog', 'budgie'
and want to remove the item by index.
At the moment I have
function removeit(myindex) {
animals[myindex] = animals.pop()
}
解决方案
You want splice
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice%28%29
Array.splice(starting point, remove count);
var newArray:Array = myArray.splice(2, 1); //this removes whatever is at index 2 and returns it in a new array.
Change your function to
function removeit(myindex) {
animals.splice(myindex, 1);
}