AS3:在不同的地方拼接两个项目?
如果我有一个数组
private var temp:Array = [item1, item2, item3, item4, item5, item6, item7...etc];
和数组中项目的两个变量:
private var firstPosition;
private var secondPosition;
有没有办法同时删除这两个项目?
比如说,如果firstPosition = item4,并且secondPosition = item7...那么firstPosition = temp[3]并且secondPosition = temp[6]
但是如果我写:
temp.splice(firstPosition, 1);
那么secondPosition是它们temp[5]而不是temp[6]...因为其中一个已从数组中删除。
我一直在写:
temp.splice(firstPosition,1);
temp.splice(secondPosition-1,1);
我认为这是不对的......特别是如果 secondaryPosition 位于“temp”数组的开头(即 temp[0])。
有没有办法从数组中一次删除两个项目(如果它们不是并排的)?
If I have an array
private var temp:Array = [item1, item2, item3, item4, item5, item6, item7...etc];
and two variables for items in the array:
private var firstPosition;
private var secondPosition;
Is there a way to remove BOTH items at once?
Say, if firstPosition = item4, and secondPosition = item7...then firstPosition = temp[3] and secondPosition = temp[6]
But if I write:
temp.splice(firstPosition, 1);
Then secondPosition is them temp[5] instead of temp[6]...since one has been removed from the array.
I have been writing:
temp.splice(firstPosition,1);
temp.splice(secondPosition-1,1);
I don't think this is right...especially if secondPosition is at the beginning of the the "temp" array (i.e. temp[0]).
Is there a way to remove two items at once from an array, if they are not side-by-side??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从索引最大的位置开始移除:
这不会影响索引较低的位置。
Start removing from position with maximum index:
This will not affect positions with lower index.