JavaScript 数组筛选与求和:找出大于 60 分的学生分数并计算总和
let sum = 0; const highScores = persons.filter(person => person.score > 60); // 使用filter方法筛选出分数大于60的学生 highScores.forEach(person => sum += person.score); // 使用forEach方法遍历筛选出来的数组并计算总和 console.log(highScores.map(person => person.score)); // 输出分数数组 console.log(sum); // 输出总和
AI 优化版
原文地址:https://www.cveoy.top/t/topic/mTyi 著作权归作者所有。请勿转载和采集!