return the largest number in an array javascript code example

Example 1: javascript largest number in array

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

Example 2: get largest number in array javascript

const array1 = [1, 3, 2];

Math.max(...array1);
// expected output: 3

Example 3: Find the maximum number of an array js

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

Example 4: find highest value in array javascript

const array = [10, 2, 33, 4, 5];

console.log(Math.max(...array)
)

Example 5: Find the maximum number of an array js

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

Example 6: rite a function that takes in an array of numbers and outputs the maximum number.

function largestOfFour(arr) {
  return arr;
}
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]);

Tags:

Misc Example