forEach(),return,break,continue实现
定义需要循环的数组array
array.forEach(function(currentValue, index, arr){
currentValue--数组中的每一个对应的元素,必须
index--当前的元素对应的下标,非必须
arr --当前元素所属的数组对象,非必须
})

forEach()不支持中断,return紧紧作为跳过当前相当于for循环的continue

替换方式用every中断循环

用some代替跳过

总结:forEach的return只是跳过了,想循环到制定的用every代替,跳过也可以用some

浙公网安备 33010602011771号