Get the Max Value of an Array with JavaScript



In this article, you will learn how to get the max value of an array with JavaScript.

The Math.max() method

If you specify multiple numbers as arguments, the Math.max() method returns the maximum value among them.

The syntax is below.


To get the max value of the array that stores the numerical value, it is as follows.


Get the Max Value of an Array

Below is the sample code to get the maximum value of the array.

console.log(Math.max(2, 5, 3)); // 5

console.log(Math.max(-2, -5, -3)); // -2

const array=[3,6,2,9,7];
console.log(Math.max.apply(null,array)); // 9