Javascript Reference - JavaScript min() Method








The min() method determine which number is the smallest in a group of numbers. It can accept any number of parameters.

Browser Support

min() Yes Yes Yes Yes Yes

Syntax

Math.min(n1, n2, n3,...,nX);

Parameter Values

Parameter Description
n1,n2,n3,...,nX Optional. Numbers to compare




Return Value

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.

Example


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.

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.