Remove Duplicates From Json Array And Combine Its Id's Using Node.js
In the following code newData print as follows var newData =(JSON.parse(jobData)); console.log(newData); currently it contains 5 values.it may varying [{ mode: daily, id:
Solution 1:
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
});
}
}
Post a Comment for "Remove Duplicates From Json Array And Combine Its Id's Using Node.js"