我有一个数组 'cat', 'dog', 'budgie'
想要通过索引删除其中的项。
目前我的代码是:
function removeit(myindex) {
animals[myindex] = animals.pop()
}
我有一个数组 'cat', 'dog', 'budgie'
想要通过索引删除其中的项。
目前我的代码是:
function removeit(myindex) {
animals[myindex] = animals.pop()
}
你需要使用splice方法。
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.
将您的函数更改为
function removeit(myindex) {
animals.splice(myindex, 1);
}
myArray.removeAt(myIndex); // removes the element at the specified index, modifying the array without making a copy
http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#removeAt()
animals[myindex] = null
吗?你想要最终的结果是什么? - Sam DeHaan