js minimum value in array code example
Example 1: javascript get minimum value in array
// Getting min value
var arr = [5,1,9,5,7];
var min = Math.min(...arr);
console.log(min); // 1
// Getting max value
var arr = [5,1,9,5,7];
var min = Math.max(...arr);
console.log(min); // 9
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);