一、some 循环
const arr = ['Jack','Mike','Judy','Andy']
/**
arr.forEach((item,index) => {
if(item === 'Mike'){
// forEach() 方法循环会把数组循环个遍之后才停止,中间无法停止,对性能消耗(浪费)较大
console.log(index)
}
})
*/
arr.some((item,index) => {
if(item === 'Mike'){
console.log(index)
// 找到对应的项之后,通过 return 终止循环,节省性能消耗
return true
}
})
一、some 循环
const arr = ['Jack','Mike','Judy','Andy