I am trying to remove duplicate entries based on the id for the following json, but it seems I am not able to parse the JSON correctly, My array of JSON is as follows:
[ '{"entries":[{"name":"sample","id":"8d"},{"name":"sample","id":"57"},{"name":"sample","id":"acc"}]}\n',
'{"entries":[{"name":"sample","id":"8d"},{"name":"sample","id":"50"},{"name":"sample","id":"ac"}]}\n',
'{"entries":[{"name":"sample","id":"8d"},{"name":"sample","id":"50"},{"name":"sample","id":"ac"}]}\n',
'{"entries":[{"name":"sample","id":"8d"},{"name":"sample","id":"50"}]}\n',
]
the output should be
{"entries":[{"name":"sample","id":"8d"},{"name":"sample","id":"57"},{"name":"sample","id":"acc"}]}
My Code is as follows:
removeDups: async function(listent){
for (i = 0; i < listent.length; i++){
console.log(listent.length)
for (j = 0; j < listent.length; j++){
console.log(listent[j])
}
var standardsList = this.arrUnique(listent);
console.log("standard", standardsList)
}
},
arrUnique: function (arr) {
var cleaned = [];
arr.forEach(function(itm) {
var unique = true;
cleaned.forEach(function(itm2) {
if (_.isEqual(itm, itm2)) unique = false;
});
if (unique) cleaned.push(itm);
});
return cleaned;
}
accand57are the uniqueids, but because the first itemsids are all the same, theidused will be theidshared by all of them, is that the rule? Find the uniqueid, or use whatever ID is shared by all?