JS - includes()

includes()方法,在字符串中使用时,相当于indexOf(),查询成功返回true,失败返回false

'abc'.includes('a') // true

'abc'.includes('d') // false

在数组中使用时,可以查询某个元素是否包含在数组中(只能查询Number,String类型的元素)

[1 , 2, 3].includes(0)  // false

['1' , '2', '3'].includes('1')  // true

猜你喜欢

转载自blog.csdn.net/sinat_33184880/article/details/87606239