I am having trouble filtering through this array that contains objects. An explanation would be greatly appreciated.
Instructions:
// Using filter(), return only your friends of the array of people below. //Assign it to a variable called 'trueFriends'.
My Solution:
var trueFriends = [];
peopleIknow.filter(function(){
for(var i = 0; i < peopleIknow.length; i++){
if (peopleIknow[i].friend == true){
trueFriends.push(peopleIknow[i]);
}
}
});
var peopleIknow = [
{ name: "Steve", friend: true },
{ name: "Dan", friend: false },
{ name: "Bart", friend: true },
{ name: "Sarah", friend: false },
{ name: "Michelle", friend: false },
{ name: "Holly", friend: true }
];