Is there a way to determine true or false if there are any duplicates within an object array?
arr = [
{ nr:10, name: 'aba' },
{ nr:11, name: 'cba' },
{ nr:10, name: 'aba' }
]
arr2 = [
{ year:2020, city: 'Aaa' },
{ year:2010, city: 'Bbb' },
{ year:2020, city: 'Aaa' }
]
While there are numerous solutions available for checking duplicate values, what if we need to check the entire object? Would using a foreach loop be necessary?
const result: T[] = [];
for (const item of array) {
if (!result.includes(item)) {
result.push(item);
}
}
return result;