JS的filter函数

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']

评论

发表评论

了解 数据控|突破是我们的每一步 的更多信息

立即订阅以继续阅读并访问完整档案。

继续阅读