forEach跳出循环

2017-11-15  本文已影响0人  Aklan

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
}
上一篇 下一篇

猜你喜欢

热点阅读