/ 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
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
You need to login to post a comment.
