Reputation: 698
I have a very large json like :
raw_obj= {"001" : {....}, "002" : {....}};
and I have an another json object which is just returned from server :
search_result = {["001", "005", "123"]};
I want to do something like
$.each(search_result, function(i,val){
alert(raw_obj.search_result[i]);
});
Is it possible? I don't want to loop through those 2 objects because in practical, there will be have around 2000 elements in a "raw_json". Which means the worst case is 2000x2000 times loop per one query.
Upvotes: 3
Views: 978
Reputation: 4525
var raw_obj= {"001" : {'...'}, "002" : {'...'}};
var search_results = ["001", "005", "123"]; // just an array
$.each(search_results, function(i, result) {
alert(raw_obj[result]);
});
The search results are an array (ie, list), not an object (ie, map) and so the syntax should be modified as above. If you have no control over the server response, use string parsing to build a new array.
Upvotes: 1