js判断一个元素是否在数组中的两种方法
1.js判断一个元素是否在数组中
(1).let arr = [1,2,3];
arr.includes(1) // true
arr.includes(5) //false
(2).a=["1", "3", "2", "3", "0"];
console.log(a.indexOf ('3'));//1
console.log(a.indexOf ('4'));//-1
1.js判断一个元素是否在数组中
(1).let arr = [1,2,3];
arr.includes(1) // true
arr.includes(5) //false
(2).a=["1", "3", "2", "3", "0"];
console.log(a.indexOf ('3'));//1
console.log(a.indexOf ('4'));//-1