How can I check for possible duplicates in an array? The possible duplicates in my case is a match in 2 objects in the array.
For example, I have the input:
const input = [
{
id: 1,
name: "Test 1",
value: 5,
date: '2021-01-01'
},
{
id: 2,
name: "Test 2",
value: 4,
date: '2021-01-01'
},
{
id: 3,
name: "Test 3",
value: 5,
date: '2021-01-01'
},
{
id: 4,
name: "Test 4",
value: 5,
date: '2021-03-01'
},
{
id: 5,
name: "Test 1",
value: 15,
date: '2021-01-21'
},
];
In this case the objects with id 1 and 3 are possible duplicates because they have the same value and date. I'm creating a new array for my output:
let output = [];
for(const x of input) {
output.push(
{
id: x.id,
name: x.name,
value: x.value,
date: x.date,
duplicate: // here is where I would like to set it to true or false
}
);
}
Is there a way to do it without looping the array and check the value and date for every instance?
Thanks