You could check the length
of the new array and return either the array or null
.(您可以检查新数组的length
,然后返回array或null
。)
function findFirstDentist(people) {
let firstDentistFound = people.filter(dentist => dentist.isDentist);
return firstDentistFound.length
? firstDentistFound
: null;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…