-3

According to the docs here, https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/max I should be able to use an array, right?

https://jsfiddle.net/utkLh4p6/

var a = [875, 551];
console.log( Math.max(a) ); // NaN
j08691
  • 204,283
  • 31
  • 260
  • 272
somebodysomewhere
  • 1,102
  • 1
  • 13
  • 25

2 Answers2

3

You may think you can pass an array because of the syntax:

Math.max([value1[, value2[, ...]]])

The brackets in this syntax indicate that the value is optional, not that it is a member of an array.

Jamie
  • 5,994
  • 1
  • 18
  • 15
1
 Math.max(...a)

You need to spread it.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151