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.
Asked
Active
Viewed 3,395 times
1
1 Answers
6
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);

GregL
- 37,147
- 8
- 62
- 67