I need to check if an array contains duplicated values.
Lets say I have the following array of arrays:
array = [
{ id: 123, name: 'Emily', address: 'UK' },
{ id: 123, name: 'Ross', address: 'USA' },
{ id: 157, name: 'Joey', address: 'Italy' },
];
As you can see, I have 2 arrays, aving the same ID id=123, and I need to detect these 2 rows, so we can clean the data we have.
P.S. I am only interested in checking duplication on IDs and Names at the same time.
I did the following logic, but it doesn't make sense, as it returns rows more than the existed ones:
ngOnInit() {
this.array.forEach((row) => {
this.array.find(element => {
if (element['id'] === row['id']) {
console.log(row)
}
})
})
}
The output is like:
123 Emily
123 Emily
123 Ross
123 Ross
157 Joey
My needed out output is as the following:
123 Emily
123 Ross
Here is a stackblitz.