I've been trying to work out a problem I'm having. I have an array with objects in it, like this:
var array = [
{
name: "Steven Smith",
Country: "England",
Age: 35
},
{
name: "Hannah Reed",
Country: "Scottland",
Age: 23
},
{
name: "Steven Smith",
Country: "England",
Age: 35
},
{
name: "Robert Landley",
Country: "England",
Age: 84
},
{
name: "Steven Smith",
Country: "England",
Age: 35
},
{
name: "Robert Landley",
Country: "England",
Age: 84
}
];
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:
[
{
name: "Steven Smith",
Country: "England",
Age: 35
},
{
name: "Steven Smith",
Country: "England",
Age: 35
},
{
name: "Robert Landley",
Country: "England",
Age: 84
},
{
name: "Steven Smith",
Country: "England",
Age: 35
},
{
name: "Robert Landley",
Country: "England",
Age: 84
}
];
If been trying to do
array.forEach(function(name, age){
if(array.name == name || array.age == age){
console.log(the result)
}
})
But that only checks if the values of the object is equal to them self.
Can anybody help me?
See Question&Answers more detail:
os