filter函数用来遍历整个数组并根据特定条件生成新的数组。
const participants=["Ben","Sarah","Eli","Henry","Sean","Annabel"];
const sName = participants.filter(function(element){
return element[0] === "S";
});
console.log(sName)
展开/折叠结果
(2) ['Sarah', 'Sean']
filter函数用来遍历整个数组并根据特定条件生成新的数组。
const participants=["Ben","Sarah","Eli","Henry","Sean","Annabel"];
const sName = participants.filter(function(element){
return element[0] === "S";
});
console.log(sName)
(2) ['Sarah', 'Sean']
发表评论