js get min of array code example

Example 1: get highest value from array javascript

//For Values
var arr =[1,10,3]
var min = Math.min.apply(null, arr),
    max = Math.max.apply(null, arr);

//For Objects
var arr = [{a: 1},{a: 10},{a: 3}]
var values = arr.map(val => val.a);
var max = Math.max.apply(null, values);
console.log(max)

Example 2: Find the maximum number of an array js

var arr = [1, 2, 3];
var max = arr.reduce(function(a, b) {
  return Math.max(a, b);
});

Example 3: min array javascript

const nums = [1, 2, 3]
Math.min(...nums)    // 1
Math.max(...nums)    // 3

Example 4: javascript index of min value in array

arr = [11, 10, 10];
var index = arr.indexOf(Math.max(...arr));

Example 5: javascript find the min in array of numbers

// Assuming the array is all integers,
// Math.min works as long as you use the spread operator(...).

let arrayOfIntegers = [9, 4, 5, 6, 3];
let min = Math.min(...arrayOfIntegers);
// => 3

Example 6: javascript math min array

const nums = [1, 2, 3]Math.min(...nums)    // 1Math.max(...nums)    // 3