how to find duplicate item from array using multiple object keys
There is a way to find based of multiple key find duplicate records in angular or javascript
getDuplicate(items, keys) {
let duplicates = [];
for (let i = 0; i < items.length; i++) {
let matchkey = 0;
for (let j = 0; j < keys.length; j++) {
if ((i < (items.length - 1)) && items[i + 1][keys[j]].toLowerCase() === items[i][keys[j]].toLowerCase()) {
matchkey++;
}
}
if (matchkey === keys) {
duplicates.push(items[i]);
}
}
return duplicates;
}
Example:
const duplicate= this.getDuplicate(CounterParty, ['OperatorId', 'TCID']);
No comments:
Post a Comment
Thank You For Your Great Contribution