我可以做这样的事情吗?
const array = ["foo", "bar", "hello", "etc"];
array.forEach(item => process(item)).then(() => {
//run after forEach is done processing the whole array
});
最佳答案
没有。 then 用于处理 promise 。 forEach 是同步的,因此您应该将处理后的项目保存在新数组中,然后立即执行后处理逻辑。
关于javascript - 我可以在 forEach() 数组助手之后链接 .then() 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53890506/