var arr = ["1","2","3","4"];
var item = "3";
var isContain = false;
// 方法1, 循环
for(var i=0;i<arr.length;i++){
if(arr[i]==item){
isContain = true;
break;
}
}
console.log(isContain);
isContain = false;
for(var i in arr){
if(arr[i]==item){
isContain = true;
break;
}
}
console.log(isContain);
//不能Return, 也不能break
isContain = false;
arr.forEach(function(itm,index){
isContain = true;
});
console.log(isContain);
//2. 方法2, indexOf() 方法
isContain = false;
var position = arr.indexOf(item); //返回下标
console.log(isContain>-1);
//3. 方法3, find() 与findIndex() 方法
isContain = false;
var itm = arr.find(function(ele){
return ele === item;
}); //返回元素
console.log(itm==item);
//箭头函数
isContain = false;
var itm = arr.find(ele => ele === item);
console.log(itm==item);
isContain = false;
var position = arr.findIndex(ele => ele === item); //返回下标
console.log(position===2);
//4. some() 方法
isContain = false;
isContain = arr.some(ele => ele === item); //返回布尔类型值
console.log(isContain);
//5. includes() ES6 方法,
isContain = false;
isContain = arr.includes(item);
console.log(isContain);
console