The min method in JavaScript's Math object evaluates the provided numerical arguments and returns the smallest value among them.
Syntax
The syntax for the min method is illustrated as follows:
Example
Math.min(num1,num2,...,numN)
Parameter
num1,num2,...,numN - Numbers to be compared..
Return
A minimum value of the given numbers.
JavaScript Math min method example
In this section, we will explore the min function by examining a range of examples.
Example 1
Let’s examine a straightforward example that demonstrates how to output the smallest value among a set of provided numbers.
Example
<script>
document.writeln(Math.min(22,34,12,15)+"<br>");
document.writeln(Math.min(-10,-24,-12,-20));
</script>
Output:
Output
12
-24
Example 2
Here’s an illustration of how to display the smallest element from the provided array.
Example
<script>
var arr=[13,15,12,9]
document.writeln(Math.min(...arr))
</script>
Output: