2

I already know about JavaScript's Math.max(13, 24, n) which returns the max number from the arguments passed but what I want to know is how to get a max number from a JavaScript array like: Math.max( [23, 482, 84, 0, 3] ) where Math.max doesn't works.

0

1 Answer 1

7

Use the .apply() function to essentially "split" the array into separate arguments.

Math.max.apply(Math, some_array);

Or, in ES6:

Math.max(...some_array);
Sign up to request clarification or add additional context in comments.

Comments