- Instant help with your JavaScript coding problems

Get the maximum value in an array using JavaScript

Question:
How to get the maximum value in an array using JavaScript?
Answer:
const myArray = [1, 14, 32, 7];

const maxValue = Math.max(...myArray);

console.log(maxValue); // 32
Description:

In modern JavaScript getting the maximum value in an array is quite simple by using the Math.max function and the spread ... operator.

The Math.max() function returns the largest of the zero or more numbers given as input parameters, or NaN if any parameter isn't a number and can't be converted into one. The result is -Infinity if no parameters are provided.

Reference:
Math.max reference
Share "How to get the maximum value in an array using JavaScript?"