有人可以帮助我理解为什么:
const people = [{
name: "Carly",
yearOfBirth: 1942,
yearOfDeath: 1970,
},
{
name: "Ray",
yearOfBirth: 1962,
yearOfDeath: 2011,
},
{
name: "Jane",
yearOfBirth: 1912,
yearOfDeath: 1941,
},
];
const findTheOldest = function(array) {
let alivePeople = array.filter(function(person) {
console.log(person.yearOfDeath);
if (person.yearOfDeath === true) {
console.log(person);
return true;
}
});
return alivePeople;
};
console.log(findTheOldest(people))Run Code Online (Sandbox Code Playgroud)
正在显示https://i.stack.imgur.com/H3p5Q.png?
我期望它返回 people 数组中的所有对象。我试图编写代码来过滤掉没有死亡一年的人。