how to see lowest number in array javascript code example
Example 1: find smallest number in array js
//Not using Math.min:
const min = function(numbers) {
let smallestNum = numbers[0];
for(let i = 1; i < numbers.length; i++) {
if(numbers[i] < smallestNum) {
smallestNum = numbers[i];
}
}
return smallestNum;
};
Example 2: finding the smallest number in an array javascript
var arr = [5,1,9,5,7];
var smallest = arr[0];
for(var i=1; i<arr.length; i++){
if(arr[i] < smallest){
smallest = arr[i];
}
}
console.log(smallest);