for和forEach的区别

    const selectList = []
      for (let i = 0; i < this.virtualAccountSelectList.length; i++) {
        const item = this.virtualAccountSelectList[i]
        const obj = {
          transferAmount: item.transferAmount,
          virtualAccountName: item.virtualAccountName,
          virtualAccountNum: item.virtualAccountNum
        }
        if (obj.transferAmount === '') {
          this.$message({ message: '转账金额不能为空', type: 'error' })
          return
        } else {
          selectList.push(obj)
        }
      }

如果要想在条件不满足时,提示内容并跳出循环就用for ,forEach会一直循环无法拦截

posted @ 2022-06-06 18:28  博客天天写  阅读(28)  评论(0编辑  收藏  举报