JavaScript Math.max() Method
The Math.max() static method returns the largest of the numbers passed to it. Spread an array into it to find the array's maximum.
Description
The Math.max() static method returns the largest of its arguments. To find the maximum of an array, spread it: Math.max(...arr). With an empty array this returns -Infinity, and with very large arrays (hundreds of thousands of elements) spreading can exceed the argument limit, in which case a loop or reduce() is safer.
Combined with Math.min(), it clamps a value into a range: Math.min(Math.max(value, min), max).
If any argument is NaN, or can't be converted to a number, the result is NaN. Arrays can't be passed directly; Math.max([1, 2]) converts the array to a string first and gives NaN, which is why spreading is needed.
Syntax
Math.max(value1, value2, ...)Parameters
- value1, value2, ...Numbers to compare.
Return Value
The largest number, -Infinity with no arguments, or NaN if any argument can't be converted to a number.
Example
Browser Support
The following information will show you the current browser support for the Math.max() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





