1

Assume I have an Array of jQuery objects. I would like to search in array and find out such a key exists are not. NOTE: The objects are not of same pattern

Ex:

a = [  { "chart_type" : 4}, 
       { "x_axis" : { "field_type" : 5, "name" : "priority" } },
       { "y_axis" : { "field_type" : 3, "name" : "created_at" }}

    ]

I would like to search from the above, if key such as "chart_type" exists or not. If yes, I would like to get the value.

a.find("chart_type").value // Need something like this

I tried the following.

jQuery.grep(chart_hash, function(key,value){
    if(key == "chart_type")
      return value
     });

However, the above doesn't work. Please help.

ramya
  • 275
  • 1
  • 5
  • 13

1 Answers1

0

Use jQuery.each

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

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

})
levi
  • 22,001
  • 7
  • 73
  • 74
  • Thanks for your answer. But it doesnt work for me. My array contains jQuery object. So when i loop through, I am getting the 'key' to be index and 'value ' as object. – ramya Mar 16 '15 at 05:42