gpt4 book ai didi

arrays - flash as3 - 如何在数组中找到对象的索引

转载 作者:行者123 更新时间:2023-12-04 22:08:07 25 4
gpt4 key购买 nike

你如何在 flash actionscript 3 中找到一个对象在数组中的索引/位置?我试图在循环中设置一个条件,如果对象的 id 等于 current_item 变量,我可以返回它在数组中的位置。

最佳答案

像这样的事情可能会帮助你 - 这个例子返回值 7 的位置:

private var _testArray:Array = new Array(5, 6, 7, 8, 9, 8, 7, 6);

public function ArrayTest()
{
trace (_testArray.indexOf(7));
//Should output 2
}

所以对于您的需求:
 item variableToLookFor = 9 // Your variable here

private var _testArray:Array = new Array(5, 6, 7, 8, 9, 8, 7, 6);

public function ArrayTest()
{
trace (_testArray.indexOf(variableToLookFor));
//Should output 4
}

如果您的项目不存在,这将返回 -1,否则它将输出数组中的位置。

如果您需要更多信息,可以查看 here 以获取有关 AS3 阵列的文章。

关于arrays - flash as3 - 如何在数组中找到对象的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5093166/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com