标签:code numbers number 执行 function pre 使用技巧 大于 ble
例如,将数组中的项的值加倍,然后只选择那些大于50的项
const numbers = [10, 20, 30, 40]; const doubledOver50 = numbers.reduce((finalList, num) => { num = num * 2; //(map) //filter number > 50 if (num > 50) { finalList.push(num); } return finalList; }, []); doubledOver50; // [60, 80]
var cars = [‘‘宝马‘,‘奔驰‘,‘奔驰‘,‘特斯拉‘,‘宝马‘,‘丰田‘]; var carsObj = cars.reduce(function(obj,name){ obj [name] = obj [name]?++ obj [name]:1; return obj; },{}); carsObj; // => {宝马:2,奔驰:2,特斯拉:1,丰田:1}
标签:code numbers number 执行 function pre 使用技巧 大于 ble
原文地址:https://www.cnblogs.com/pjl43/p/10747585.html