Why is math.max() returning NaN on an array of integers?

后端 未结 4 1877
太阳男子
太阳男子 2020-11-28 13:05

I am trying to get the highest number from a simple array:

data = [4, 2, 6, 1, 3, 7, 5, 3];

alert(Math.max(data));

I have read that if eve

4条回答
  •  我在风中等你
    2020-11-28 13:52

    If you have to use the Math.max function and one number of the array might be undefined, you could use:

    x = Math.max(undefined || 0, 5)
    console.log(x) // prints 5
    

提交回复
热议问题