Suzed Suzed - 4 months ago 9
jQuery Question

Push value into object with the same values

can someone take a quick look at my code? im trying to push a value into an object with if the same value name as the array in my loop.

$(document).ready(function(){

var obj = $.parseJSON(data);
column_data = obj.series.data.series.data;
drilldown_data = obj.drilldown.drilldown.series;

$.each(column_data, function (key, val) {
if(drilldown_data[key].id == val.name){
drilldown_data.push(val.y);
};
});
console.log(drilldown_data);


So after i do a console.log on drilldown_data it should look like this. With the y key inside of the object because the id is the same as the name.

0 : Object
data:Array[2]
id:"test"
name:"test"
y:154

Answer

try this:

$.each(column_data, function (key, val) {
    if(drilldown_data[key].id == val.name){
      drilldown_data[key]['y']=val.y;
    };
  });
Comments