Skip to content
Advertisement

Find duplicate values in objects with Javascript

I’ve been trying to work out a problem I’m having. I have an array with objects in it, like this:

JavaScript

I want to get the objects that have duplicate values in them and based on what values to search for. I.e , I want to get the object that has a duplicate value “name” and “age” but nog “country” so I will end up with:

JavaScript

If been trying to do

JavaScript

But that only checks if the values of the object is equal to them self.

Can anybody help me?

Advertisement

Answer

You can use 2 reduce. The first one is to group the array. The second one is to include only the group with more than 1 elements.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement