find the biggest number in array js code example

Example 1: greater number in arraya jd

var array = [3 , 6, 2, 56, 32, 5, 89, 32];
var largest= 0;

for (i=0; i<=largest;i++){
    if (array[i]>largest) {
        var largest=array[i];
    }
}




console.log(largest);

Example 2: javascript largest number in array

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

Example 3: javascript hwo to return largest value with index

var a = [0, 21, 22, 7];
var indexOfMaxValue = a.reduce((iMax, x, i, arr) => x > arr[iMax] ? i : iMax, 0);

document.write("indexOfMaxValue = " + indexOfMaxValue); // prints "indexOfMaxValue = 2"

Example 4: javascript set value to the largest value in an array

//get min/max value of arrays
function getArrayMax(array){
   return Math.max.apply(null, array);