The min()
method determine which number is the smallest in a group of numbers.
It can accept any number of parameters.
min() |
Yes | Yes | Yes | Yes | Yes |
Math.min(n1, n2, n3,...,nX);
Parameter | Description |
---|---|
n1,n2,n3,...,nX | Optional. Numbers to compare |
The lowest number of the arguments.
It returns -Infinity if no arguments are given.
It returns NaN if one of the arguments is not numbers.
var max = Math.max(3, 5, 3, 6);
console.log(max); // 6
var min = Math.min(3, 5, 3, 6);
console.log(min); //3
The code above generates the following result.
To find the maximum or the minimum value in an
array, you can use the apply()
method as follows:
var values = [1, 2, 3, 4, 5, 6, 7, 8];
var min = Math.min.apply(Math, values);
console.log(min);//1
The code above generates the following result.