I have the following array:
PeopleList
[ {id:1, name:"Brian", status:"active"}, {id:2, name:"Mary", status:"active"},
{id:3, name:"John", status:"pending"}, {id:4, name:"Steph", status:"pending"},
{id:5, name:"Peter", status:"inactive"}
]
statusList
[ 'active', 'pending']
I want to filter the object array to only the statusList so I did the following:
var filteredPeople =PeopleList.map(person => {
for (var i=0; i<=statusList.length; i++){
if(statusList[i] == person.active)
return {...person};
}
});
While the person objects return correctly, I also get "undefined" for objects that didn't pass the conditional statement.
So my result is:
[object, object, object,object, undefined ]
How can I make it so that if the conditional does not pass, I remove that object from the list?