maximum array size javascript code example

Example 1: 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 2: get max element of array javascript

const maxMinArray = (a,b,...c) =>{
    //we are concatinating this array
    let array = [a,b];
    let newArray = array.concat(c);
    //now let's get started with the excersice
    let max = 0;
    for(let number of newArray){
        if(max<number){
            max = number;
        }
    }
    let min = max;
    for(let number of newArray){
        if(number<min){
            min = number;
        }
    }
    return console.log(max + ' ' + min)
}
//example: 
maxMinArray(12,14,15,23)

Example 3: javascript max array

Math.max(1, 2, 3)    // 3
Math.min(1, 2, 3)    // 1

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

Example 4: Find the maximum number of an array js

function getMaxOfArray(numArray) {
    return Math.max.apply(null, numArray);
}

Example 5: js max array

Math.max(...array);

Example 6: Find the maximum number of an array js

Math.max(10, 20);   //  20
Math.max(-10, -20); // -10
Math.max(-10, 20);  //  20