(js)循环判断找到满足条件的单项后结束循环

2023-12-28 15:44:13

(js)循环判断找到满足条件的单项后结束循环


forEach结束循环正确用法:运用抛出异常(try catch)
if (newVal != "") {
  try {
    this.gxList.forEach((ele) => {
      if (this.processId === ele.id) {
        this.gxDisabled = false;//自己的逻辑
        throw "StopIteration";
      } else {
        this.gxDisabled = true;//自己的逻辑
      }
    });
  } catch (e) {
    if (e !== "StopIteration") throw e;
  }
}

1.中断forEach:https://blog.csdn.net/lwf3115841/article/details/131103069

2.https://blog.csdn.net/qq_37899792/article/details/97117010

文章来源:https://blog.csdn.net/qq_44754635/article/details/135269436
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。