我有一個數組,看起來像這樣:搜索多維數組的JavaScript
selected_products[0]=["r1","7up",61,"Albertsons"]
selected_products[1]=["r3", "Arrowhead",78,"Arrowhead "]
selected_products[2]=["r8", "Betty Crocker Cake Mix (Variety)",109,"Arrowhead "]
...
我怎麼能根據每個項目(R1,R2中的第一項搜索項目在這個數組中,.. ) 數組是巨大的,我在尋找一個快速獲得此數組 我用jQuery函數jQuery.inArray結果的有效方式,但它無法找到我的陣列中的任何東西,我用這種方式:
alert($.inArray(["r1","7up",61,"Albertsons"],selected_products))// it returns -1
alert($.inArray("r1",selected_products))//this also returns -1
你不想回你要搜索的內容,只需確定它的存在與否? – Briz 2012-01-10 19:38:53
@Briz我想獲得該數組中的項目索引,例如它具有「r1」例如 – 2012-01-10 19:46:25
@AymanJitan我更新了我的問題,現在它可以返回所有索引的列表,以防萬一有多個 – ajax333221 2012-01-10 20:25:44