AS3数组的索引中删除 [英] as3 array remove by index

查看:112
本文介绍了AS3数组的索引中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数组猫,狗,鹦鹉

和希望通过索引中删除该项目。

目前,我有

 函数removeit(myindex){
    动物[myindex] = animals.pop()
}
 

解决方案

您想拼接

<一个href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Array.html#splice%28%29">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);
}

这篇关于AS3数组的索引中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆