【问题标题】:jQuery - Search in Array of Objects [duplicate]jQuery - 在对象数组中搜索 [重复]
【发布时间】:2015-05-18 04:06:34
【问题描述】:

假设我有一个 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
     });

但是,上述方法不起作用。请帮忙。

【问题讨论】:

标签: javascript jquery arrays search


【解决方案1】:

使用jQuery.each

$.each(chart_hash, function(index,value){

    $.each(value,function(key,val){
         if(key == "chart_type")
          return val
         });
     })

})

【讨论】:

  • 感谢您的回答。但这对我不起作用。我的数组包含 jQuery 对象。因此,当我循环遍历时,我将“键”作为索引,将“值”作为对象。
猜你喜欢
  • 1970-01-01
  • 2013-09-03
  • 2018-03-25
  • 2013-09-08
  • 2020-12-05
  • 2020-03-20
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多