jquery - Search an associate array / hash in Javascript -
this question has answer here:
i have array looks
var data = [ {"target": "production", "datapoints": [[165.0, 136], [141.0, 176], [null, 176]]}, {"target": "test", "datapoints": [[169.0, 100], [151.0, 160], [null, 120]]}, {"target": "backup", "datapoints": [[1.0, 130], [32.0, 120], [13.0, 130]]} ]
is possible search array return hash contains example "production"
{"target": "production", "datapoints": [[165.0, 136], [141.0, 176], [null, 176]]}
i looked @ http://api.jquery.com/jquery.inarray/ didn't know how use it.
you can do:
var target = "production"; var result = $.grep(data, function(e){ return e.target == target; }); console.log(result);
Comments
Post a Comment