There are syntax errors in your code, missing ,
and quotes for mode
values, after fixing the errors, you can try the following, neu
array’s id
properties are arrays and o
here refers to the original array.
var neu = [], l = o.length;
for (var i = 0; i < l; i++) {
var f = neu.filter(function(e, _) {
return e.os === o[i].os;
});
if (f.length) {
f[0].id.push(o[i].id);
} else {
neu.push({
os: o[i].os,
id: [o[i].id],
mode: o[i].mode
});
}
}
2
solved remove duplicates from json array and combine its id’s using node.js