Math.min([number1, number2, ... number_n]);
Parameters or Arguments
number1, number2, … number_n Optional. The numbers that will be evaluated to determine the smallest value.
The min() feature returns the smallest cost from the numbers provided.
If no parameters are provided, the min() feature will return Infinity.
If any of the parameters provided are now not numbers, the min() function will return NaN.
Math is a placeholder object that carries mathematical functions and constants of which min() is one of these functions.
console.log(Math.min(5, 10)); console.log(Math.min(60, 40, 20)); console.log(Math.min(-3, -6, -9, -12));
In this example, we have invoked the min() characteristic the use of the Math class.
We have written the output of the min() feature to the internet browser console log, for demonstration purposes, to exhibit what the min() function returns.
The following will be output to the web browser console log:
5 20 -12
In this example, the first output to the console log back 5 which is the smallest of the values 5 and 10.
The second output to the console log lower back 20 which is the smallest of the values 60, forty and 20.
The third output to the console log returned -12 which is the smallest of the values -3, -6, -9 and -12.
Using the min() characteristic to locate the Largest Value in an Array
Finally, we are going to take a seem at how to use the min() characteristic to discover the smallest cost in an array.
var totn_array = [2, 4, 6, 8, 10]; console.log(Math.min(...totn_array));
The following will be output to the internet browser console log:
In this example, the min() approach back 2 which is the smallest cost from the array called totn_array. This array consisted of 5 factors with the numeric values: 2, 4, 6, 8 and 10.