[JavaScript] How to find min number from an array?
I want to find the minimum number from an array, how can I do that in Javascript?
3 Answers
3 years ago by Jahaan
You can use Math.min()
method to find the minimum number present in a given array.
Usage:
Math.min(...array)
Try with example here : https://onecompiler.com/javascript/3xnp9m9g3
3 years ago by Meera
<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>
3 years ago by Manish Sahu
-
create a temp variable, set its value to first index of array
-
iterate over array
-
check if arrays current element is less than the temp
-
if yes
- set temp = current array element
3 years ago by 18C060 MOHIT SHARMA