我有一个看起来像这样的数组
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]]}
]
Run Code Online (Sandbox Code Playgroud)
是否可以搜索此数组以返回包含的哈希值 "production"
{"target": "production", "datapoints": [[165.0, 136], [141.0, 176], [null, 176]]}
Run Code Online (Sandbox Code Playgroud)
我查看了这个http://api.jquery.com/jQuery.inArray/,但不知道如何使用它.
你可以做:
var target = "production";
var result = $.grep(data, function(e){ return e.target == target; });
console.log(result);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7540 次 |
| 最近记录: |