Below is the code I am trying out to filter out the array for males and females. But it seems it is returning the whole array again in both male and female variables.
const male = await familyTree.filter(async(uncle) => {uncle.gender === 'Male'});
const female = await familyTree.filter(async(aunt) => {aunt.gender === 'Female'});
My array of objects:
var familyTree= [
{
name: 'Ish',
gender: 'Male',
grandfather: 'null',
grandmother: 'null',
father: 'Shan',
mother: 'Anga',
wife: {}
},
{
name: 'Vich',
gender: 'Male',
grandfather: 'null',
grandmother: 'null',
father: 'Shan',
mother: 'Anga',
wife: {
name: 'Lika',
husband: 'Vich',
fil: 'Shan',
mil: 'Anga',
children: [Array]
}
},
{
name: 'Aras',
gender: 'Male',
grandfather: 'null',
grandmother: 'null',
father: 'Shan',
mother: 'Anga',
wife: {
name: 'Chitra',
husband: 'Aras',
fil: 'Shan',
mil: 'Anga',
children: [Array]
}
},
{
name: 'Satya',
gender: 'Female',
grandfather: 'null',
grandmother: 'null',
father: 'Shan',
mother: 'Anga',
husband: 'Vyan',
children: [ [Object], [Object], [Object] ]
}
]
When I print males and females in the console it is returning the whole array again without filtering them. What could be the reason?