js数组includes与indexOf区别

includes

let arr=[1,true,3];
a.includes(1)  //=>true;
a.includes(11)  //=>false;

indexOfqu

let a=[1,2,3,NaN];
a.includes(1)  //=>0
a.indexOf(11)   //=>-1

区别

includes认为NaN与自身相等。

let a=[1,2,3,NaN];
a.includes(NaN)  //=>true
a.indexOf(NaN)   //=>-1

上一篇:Java中indexof()的用法


下一篇:find(), findIndex(),indexof使用方法和区别