在Flex中,测试在flex中包含特定值的数组

Din*_*mar 2 apache-flex arrays

我有一个数组,其中包含许多值.我只是想要一个简单而好的方法来检查数组是否包含特定值.提前致谢.

RIA*_*tar 9

像这样使用Array.indexOf():

if (myArray.indexOf(item) != -1) trace("item exists");
else trace("nope! can't find it")
Run Code Online (Sandbox Code Playgroud)

indexOf如果项目存在则返回索引,如果不存在则返回-1.