1、apply
var arr = [3, 8, 6, 2, 1]; Math.max.apply(null, arr);
2、reduce
var arr = [3, 8, 6, 2, 1]; function compareMax(prev, next) { return Math.max(prev, next); } arr.reduce(compareMax);
3、ES6
var arr = [3, 8, 6, 2, 1]; Math.max(...arr);
时间: 2024-11-05 03:17:21