Smallest number in JavaScript can be find in different ways we can use Math.min() in easy way.
We can find the smallest number from given list.
We use Math.min() function to find the smallest number.
min is a predefined number that is available in Math class.
Math.min() takes set of arguments or array to find the minimum value
Example
Math.min(3,4,7,7,1,5,4,8,9,6);
Here we are passing number of elements.
var numbers = [55,43,67,48,32,77,5,51,66,34,65,87,98];
const min = Math.min(…numbers);
Here we are passing array in min().
If no argument is passes iin Math.min() then on printing this it will print Infinity.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | <!DOCTYPE html> <html> <head> <title>Smallest number in an array javascript</title> </head> <body> <h2>Find the smalleste number in array</h2> <h2 id="sno">sdf</h2> <script> var numbers = [55,43,67,48,32,77,5,51,66,34,65,87,98]; const min = Math.min(...numbers); document.getElementById("sno").innerHTML ="Smallest Number is "+min; </script> </body> </html> |
This above example will print the Smallest number in JavaScript.
Read More