1、抛出错误 try…catch
var arr = [1, 2, 3, 4, 5]
try {
arr.forEach(item => {
if (item == 4) {
return new Promise()
}
console.log(item)
})
} catch (error) {
console.log(error)
}
2、返回一个pending状态的promise
var arr = [1, 2, 3, 4, 5]
arr.forEach(item => {
if (item == 4) {
return new Promise()
}
console.log(item)
})