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

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/b7223058/article/details/78839386

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

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

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

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





猜你喜欢

转载自blog.csdn.net/b7223058/article/details/78839386
今日推荐