I want to insert the values from one array to another array if the values matched.
These are my arrays.
var names = [{key: 'Apple'}, {key: 'Dell'}, {key: 'Xitrix'}];
var data = [
{enum_name:'Apple', date:'2000-12-15', accomp: 12},
{enum_name:'Dell', date:'2000-12-15', accomp: 8},
{enum_name:'Apple', date:'2000-12-16', accomp: 12},
{enum_name:'Xitrix', date:'2000-12-16', accomp: 12},
{enum_name:'Dell', date:'2000-12-17', accomp: 8},
{enum_name:'Xitrix', date:'2000-12-17', accomp: 12},
];
Then i want to insert data.date and data.accomp into the array names with a specific key (e.g. attrib: [arrays];
I have this code but it doesn't insert all the matched data to the key attrib.
var counts = 0;
_.each(names, function(v, k){
_.each(data, function(val, key){
if(v.key == val.enum_name){
var date = val.date;
var accomp= val.accomp;
names[k].attrib= [[date, accomp]];
console.log(counts);
counts++;
}
});
counts = 0;
//names[k]['values'] = 'test';
});
i want an output like this.
names = [
{key: 'Apple', attrib: [['2000-12-15', 12], ['2000-12-16', 12]]},
{key: 'Dell', attrib: [['2000-12-15', 8], ['2000-12-17', 8]]},
{key: 'Xitrix', attrib: [['2000-12-16', 12], ['2000-12-17', 12]]}
];
{'2000-12-17', 12}That is invalid syntax, what do you actually want there?{date, accomplished}did you meanaccomp?