Find index of NaN in a javascript array

前端 未结 3 2140
清歌不尽
清歌不尽 2021-01-04 07:16
[1, 2, 3].indexOf(3) => 2

[1, 2, NaN].indexOf(NaN) => -1

[1, NaN, 3].indexOf(NaN) => -1
3条回答
  •  抹茶落季
    2021-01-04 07:53

    NaN is defined not to be equal to anything (not even itself). See here: http://www.w3schools.com/jsref/jsref_isNaN.asp

提交回复
热议问题