forEach跳出循环

for循环可以用break或return跳出循环,forEach不能
jquery的$.each也不能用break,可以用return

try{
    arr.forEach((item,index)=>{
        if(){
                 //
             foreach.break = new Error("StopIteration")
            }
     })
 }catch(e){
    if(e.message === "foreach is not defined") {
           //console.log("...")
     }else throw e
}

你可能感兴趣的:(forEach跳出循环)