includes:判断某个值是否在数组中,返回true/false
indexOf():返回该值在数组中的索引,如果没有则返回-1
in:判断索引是否在数组中,比如0,1,2,3。注意不是值,而是索引
let arr = ['apple','banana','pear'] console.log('apple' in arr) //false console.log(1 in arr) // true console.log(arr.indexOf("apple")) // 0 console.log(arr.includes('pear')) // true console.log(arr.includes(1)) // false
作者:椰果粒
链接:https://www.jianshu.com/p/ee6f25afb746