The Math.max function can accept any arbitrary number of arguments:
Syntax:
Math.max([value1[,value2[, ...]]])
Usage:
var max = Math.max(num1, num2, num3);
For example:
console.log(Math.max(1,2,3,4,5,6)); // 6
You could even use it to get the maximum value of an array of numbers with the help of apply:
function maxOfArray(array) {
return Math.max.apply(Math, array);
}
let array = [1,2,3,4,5,6];
console.log(maxOfArray(array)); // 6
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…