js——获取数组中的最大值

reduce() 方法接收一个函数作为累加器,数组中的每个值(从左到右)开始缩减,最终计算为一个值。

let  arr = [1, 3, 5, 7,10]      
let max = arr.reduce((key1, key2) => {
    
    
return key1 = key1 > key2 ? key1 : key2
});
console.log(max)   // 10

猜你喜欢

转载自blog.csdn.net/qq_43201350/article/details/121703848
今日推荐