假设我有一个 jQuery 对象数组。我想在数组中搜索并找出这样的键是否存在。 注意:对象的图案不同
例如:
a = [ { "chart_type" : 4},
{ "x_axis" : { "field_type" : 5, "name" : "priority" } },
{ "y_axis" : { "field_type" : 3, "name" : "created_at" }}
]
我想从上面搜索“chart_type”等键是否存在。如果是的话,我想得到这个值。
a.find("chart_type").value // Need something like this
我尝试了以下方法。
jQuery.grep(chart_hash, function(key,value){
if(key == "chart_type")
return value
});
但是,上面的方法不起作用。请帮忙。
最佳答案
$.each(chart_hash, function(index,value){
$.each(value,function(key,val){
if(key == "chart_type")
return val
});
})
})
关于javascript - jQuery - 在对象数组中搜索,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29070115/