uniapp forEach终止循环-后续代码不在执行的办法

直接上代码(使用try catch来实现终止循环)

             try {
					this.dataList.forEach((item) => {
						console.log('answerResult', item.answerResult == undefined);
						if (item.answerResult == undefined) {
							this.modelShow = true
							throw new Error("breakForEach");//停止循环
						}
					})
				} catch (e) {
					return; //结束代码 后面代码不再执行
				}

你可能感兴趣的:(uniapp,uni-app,前端,javascript)