我有以下数组:
var = array[
{"id" : "aa", "description" : "some description"},
{"id" : "bb", "description" : "some more description"},
{"id" : "cc", "description" : "a lot of description"}]
我尝试找到包含id === "bb"
. 我想出的解决方案如下:
var i = 0;
while(array[i].id != "bb"){
i++;
}
alert(i) //returns 1
有没有更简单的跨浏览器功能的方法?我试过$.inArray(id,array)
了,但它不起作用。