get smallest number in array code example
Example 1: javascript find smallest number in an array
const arr = [14, 58, 20, 77, 66, 82, 42, 67, 42, 4]
const min = Math.min(...arr)
console.log(min)
Example 2: find smallest number in array js
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 3: largest and smallest number in an array 1-100 javascript
let numArray = [95, 1, 75, 7, 12, 50, 3, 88]
numArray.slice().sort(function(a, b) {
return a - b
})
console.log('smallest: ' + numArray[0] + ', largest: ' + numArray[numArray.length - 1])
Example 4: js get smallest value of array
Array.min = function( array ){
return Math.min.apply( Math, array );
};
var minimum = Array.min(array);