如果我有一个类似的数组:
var myArray:Array = new Array("a","b","c","d","e","f","g","b");
如何搜索它以确定其中出现值的次数以及出现在哪些位置?我发现下面的代码很接近,但它只会返回第一次出现。
function findIndexInArray(value:Object, arr:Array):Number {
for (var i:uint=0; i < arr.length; i++) {
if (arr[i]==value) {
return i;
}
}
return NaN;
}
var myArray:Array = new Array("a","b","c","d","e","f","g","b");
trace(findIndexInArray("b", myArray));
// OUTPUT
// 1