This function takes the member who's index you want, and the array it belongs to. If -1 is returned, then there is no matching element. Also, it will match integers. You could probably extend it to match anything actually - even objects?
function getIndex(member,array){
var index = -1;
for(var j=0;j<array.length;j++){
if(array[j] == member){
index = j;
break;
}
}
return index;
}
e.g. for the array:
var people = new Array("Ben","Gus","Tim",4,"Coopth"
the call: getIndex("Tim",people) returns 2
and getIndex(4,people) returns 3
Hope this works for you.
b2 - benbiddington@surf4nix.com
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.