I have been attempting to identify any duplicate values within an array of objects and create a function in ES6 that will return true if duplicates are found.
arrayOne = [{
agrregatedVal: "count",
value: "Employee Full Name"
},
{
agrregatedVal: "min",
value: "Employee Full Name"
},
{
agrregatedVal: "min",
value: "Employee Full Name"
},
{
agrregatedVal: "count",
value: "Pay Date"
},
{
agrregatedVal: "count",
value: "Employee Full Name"
},
{
agrregatedVal: "min",
value: "Signature"
},
{
agrregatedVal: "min",
value: "Pay Date"
}]
This is the JSON structure provided:
There are two duplicate objects as shown below:
{
agrregatedVal: "min",
value: "Employee Full Name"
}, {
agrregatedVal: "min",
value: "Employee Full Name"
}
The rest of the objects do not concern us, only the ones with identical values. If each object value is a duplicate of another object in the same array, the function should return true.
I attempted the following approach:
this.arrayOne = this.arrayOne.filter((thing, index, self) => {
return index === self.findIndex((t) => {
return t.agrregatedVal === thing.agrregatedVal && t.value === thing.value;
});
});
However, it did not yield the desired result. How can I ensure that the function returns true when the value of each object matches that of another object?