I am trying to find the duplicate value in the array of objects and return true value in es6 function.
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"
}]
Above is the structure of the json
Here i have two object which are duplicate:
{
agrregatedVal: "min",
value: "Employee Full Name"
}, {
agrregatedVal: "min",
value: "Employee Full Name"
}
and remaining are not concerned as both values of each object are different.
If each object value is duplicate of another object of same array then it should return true.
I tried in this way:-
this.arrayOne = this.arrayOne.filter((thing, index, self) => {
return index === self.findIndex((t) => {
return t.agrregatedVal === thing.agrregatedVal && t.value === thing.value;
});
});
it dint work, how to return true if object of each value is same of another object.
return index === ..., or you should remove the curly braces.