一起来学习下新知识:介绍es6新特性以及es5和ES6如何取数组的最大值。
介绍ES6新特性:
ES5和ES6如何取数组的最大值:
// ES5 的写法
Math.max.apply(null, [14, 3, 77, 30]);
// ES6 的写法
Math.max(...[14, 3, 77, 30]);
// reduce
[14,3,77,30].reduce((accumulator, currentValue)=>{
return accumulator = accumulator > currentValue ? accumulator : currentValue
});
网友评论文明上网理性发言 已有0人参与
发表评论: