var array = ["first","second","third","fourth"]; // 执行到第3次,结束循环 array.forEach(function(item,index){ if (item == "third") { return //等于third时跳出这个循环,如何实现 } alert(item);// first,sencond }); }
var array = ["first","second","third","fourth"]; try{ // 执行到第3次,结束循环 array.forEach(function(item,index){ if (item == "third") { //等于third时跳出这个循环,如何实现 throw new Error(''); } alert(item);// first,sencond }); }catch(e){ }
这道题你会答吗?花几分钟告诉大家答案吧!
扫描二维码,关注牛客网
下载牛客APP,随时随地刷题