I have one requirement that will get json array object it looks like below(input) json i need to get dupliacte records & unquie records and load it into respective list. condition to check wether array has duplicates or not :: id
let uniqueList = [];
let dupList = [];
Array.prototype.contains = function (item) {
let filtered_item = this.filter((i) => {
return i.id === item.id
});
return !!filtered_item.length;
}
function contains(list, item) {
let filtered_item = list.filter((i) => {
return i.id === item.id
});
return !!filtered_item.length;
}
function pushToUniqueList(item) {
uniqueList.push(item);
}
function pushToDuplicateList(item) {
dupList.push(item);
}
for (let i = 0; i < objList.length; i++) {
if (uniqueList.contains(objList[i])) {
pushToDuplicateList(objList[i]);
} else {
pushToUniqueList(objList[i]);
}
}
Input : [{"obj":{"id":"1234","table":"123"}},{"obj":{"id":"1234","table":"123"}},{"obj":{"id":"12344","table":"123"}}]
output : uniqueList =[{ "obj":{ "id":"12344", "table":"123" }]
dupList =[{"obj":{"id":"1234","table":"123"}},{"obj":{"id":"1234","table":"123"}}]
I have tried with above code but its not working Please help!Thanks in advance!