as3数组按索引删除

LeB*_*eau 8 arrays indexing actionscript-3

我有一个阵列'猫','狗','budgie'

并希望按索引删除该项目.

目前我有

function removeit(myindex) {
    animals[myindex] = animals.pop()
}
Run Code Online (Sandbox Code Playgroud)

fra*_*cis 32

你想拼接

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice%28%29

Array.splice(起始点,删除计数);

 var newArray:Array = myArray.splice(2, 1); //this removes whatever is at index 2 and returns it in a new array.
Run Code Online (Sandbox Code Playgroud)

将您的功能更改为

function removeit(myindex) {
    animals.splice(myindex, 1);
}
Run Code Online (Sandbox Code Playgroud)


low*_*lly 6

使用 Flash Player 19+ 或 AIR 19+ 时,您可以使用

myArray.removeAt(myIndex); // removes the element at the specified index, modifying the array without making a copy
Run Code Online (Sandbox Code Playgroud)

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#removeAt()