主要使用 Math 的 max 和 min 方法。
let arr = [1, 2, 3, 4, 10, 20, 5, 6];
// 【ES5】
Math.max.apply(null, arr); // 20 最大值
Math.min.apply(null, arr); // 1 最小值
// 【ES6】
Math.max(...arr); // 20 最大值
Math.min(...arr); // 1 最小值
主要使用 Math 的 max 和 min 方法。
let arr = [1, 2, 3, 4, 10, 20, 5, 6];
// 【ES5】
Math.max.apply(null, arr); // 20 最大值
Math.min.apply(null, arr); // 1 最小值
// 【ES6】
Math.max(...arr); // 20 最大值
Math.min(...arr); // 1 最小值
Copyright © 2019- huatuowenda.com 版权所有 湘ICP备2023022495号-1
违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com
本站由北京市万商天勤律师事务所王兴未律师提供法律服务