How to use Math min() method in Javascript
Description
The min()
method determine which number is the smallest in a group of numbers.
It can accept any number of parameters:
Example
var max = Math.max(3, 5, 3, 6);
console.log(max); // 6/* www.j ava 2 s. c o m*/
var min = Math.min(3, 5, 3, 6);
console.log(min); //3
The code above generates the following result.
Max/Min value for an array
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.