/ Published in: ActionScript 3
If the item cannot be found then the return value is NaN. This function only returns the index of the first occurence found, so it's not very good if you have multiple occurrences of the same value in the array.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
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"); trace(findIndexInArray("c", myArray)); // OUTPUT // 2