-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
  • 197,815
  • 30
  • 248
  • 265
somebodysomewhere
  • 983
  • 1
  • 12
  • 23

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,596
  • 1
  • 19
  • 15
1
 Math.max(...a)

You need to spread it.

Jonas Wilms
  • 120,546
  • 16
  • 121
  • 140