js使用return在forEach中跳出循环无效

来源:互联网 发布:iphone7如何卸载软件 编辑:程序博客网 时间:2024/05/21 08:40

一次项目中使用forEach进行遍历,达到某一条件,希望跳出循环,代码不继续执行。

this.itemTableData.forEach(function(item, index){    if (item.taskValue == 100) {       return    }

经查询资料,得知forEach遍历并不能被终止,会被继续执行。

因此要达到所需效果,可以使用for循环,然后就可以使用break,continue,或者return跳出遍历。





阅读全文
0 0
原创粉丝点击