I have the following array:
var = array[
{"id" : "aa", "description" : "some description"},
{"id" : "bb", "description" : "some more description"},
{"id" : "cc", "description" : "a lot of description"}]
and I try to find the index of the array that contains the id === "bb". The solution I came up with is the following:
var i = 0;
while(array[i].id != "bb"){
i++;
}
alert(i) //returns 1
Is there an easier way that has cross-browser functionality? I tried $.inArray(id,array) but it doesn't work.
forloop instead ofwhileand use-1as the result if none is found - that seems to be common. I'll do you an answer I think