2025年03月03日 建站教程
es6语法有哪些去数组最大值的方法,下面web建站小编给大家详细介绍一下!
利用Math.max()取最大值
Math.max(1, 2,3,4,5,8,7,6); //8 Math.max(-10, -20); // -10
利用apply方法取最大值
console.log(Math.max.apply(null, [1, 2,3,4,5,8,7,6])); // 8
利用reduce取最大值
[1, 2,3,4,5,8,7,6].reduce((accumulator, currentValue)=>{ return accumulator = accumulator > currentValue ? accumulator : currentValue }); //8
本文链接:http://so.lmcjl.com/news/24216/