Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery-在对象数组中搜索_Javascript_Jquery_Arrays_Search - Fatal编程技术网

Javascript jQuery-在对象数组中搜索

Javascript jQuery-在对象数组中搜索,javascript,jquery,arrays,search,Javascript,Jquery,Arrays,Search,假设我有一个jQuery对象数组。我想在数组中搜索,并发现这样一个密钥不存在。 注意:对象的图案不同 例: 我想从上面搜索,如果像chart_type这样的键存在或不存在。如果是,我想得到值 a.find("chart_type").value // Need something like this 我尝试了以下方法 jQuery.grep(chart_hash, function(key,value){ if(key == "chart_type") return val

假设我有一个jQuery对象数组。我想在数组中搜索,并发现这样一个密钥不存在。 注意:对象的图案不同

例:

我想从上面搜索,如果像chart_type这样的键存在或不存在。如果是,我想得到值

a.find("chart_type").value // Need something like this
我尝试了以下方法

jQuery.grep(chart_hash, function(key,value){
    if(key == "chart_type")
      return value
     });
但是,上述方法不起作用。请帮助。

使用


查看此链接,谢谢您的回答。但这对我不起作用。我的数组包含jQuery对象。所以当我循环时,我得到的“键”是索引,“值”是对象。
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
         });
     })

})