I have a very simple array:
var arr = [{id: 1, score: 10}, {id: 1, score: 10}, {id: 3, score: 20}, {id: 4, score: 5}];
I want to remove those object which has only single occurrence e.g:
{id: 3, score: 20}
{id: 4, score: 5}
So the final output should be:
[{id: 1, score: 10}, {id: 1, score: 10}]
What I have tried so far is:
const result = [];
for (let i = 0; i < arr.length; i++) {
for (let j = i + 1; j < arr.length; j++) {
if (arr[i].id === arr[j].id && arr[i].score === arr[j].score) {
result.push({ id: arr[i].id, score: arr[i].score })
}
}
}
But this is removing my duplicates as well, e,g it gives me this result:
[{id: 1, score: 10}]
But i need this result:
[{id: 1, score: 10}, {id: 1, score: 10}]