1. includes用来判断一个数组是否包含指定的值,包含返回ture,否则为false;indexOf返回在数组中存在指定值的第一个索引,不存在返回-1
includes:
const arr1 = [1,2,3,'a','b']
console.log(arr1.includes('a'))// true
console.log(arr1.includes('c'))// false
indexOf:
const arr2 = [1,2,3,'a','b']
console.log(arr2.indexOf('a'))// 3
console.log(arr2.indexOf('c'))// -1
2. includes可以判断有NaN的元素,indexOf不能
const arr3 = [1,2,3,'a','b',NaN]
console.log(arr3.indexOf(NaN))// -1
console.log(arr1.includes(NaN))// true