get smallest number in array javascript 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: javascript minimum number in array

const min = arr => Math.min(...arr);

Example 3: find smallest length string in an array js

var arr = ["aaaa", "aa", "aa", "aaaaa", "a", "aaaaaaaa"];

console.log(
  arr.reduce((a, b) => a.length <= b.length ? a : b)
)

Example 4: js math function that returns smallest value

console.log(Math.min(2, 3, 1));
// expected output: 1

console.log(Math.min(-2, -3, -1));
// expected output: -3

const array1 = [2, 3, 1];

console.log(Math.min(...array1));
// expected output: 1

Example 5: how to find smallest number in array js

Array.min = function( array ){
    return Math.min.apply( Math, array );
};

Example 6: 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);