【发布时间】:2020-05-03 18:14:03
【问题描述】:
这是我的 forEach 循环。如何在此循环完成后调用语句?我想不通
array.forEach(item => {
console.log("Loop started");
let id = [item.id];
let type = item.type;
if (subType == "a") {
api.method(type, id)
.then(response => {
console.log("response.data :>> ", response.data);
})
.finally(() => {
console.log("finally item :>> ", item);
});
} else if (subType == "b") {
api.method(type, id)
.then(response => {
console.log("response.data :>> ", response.data);
})
.finally(() => {
console.log("finally item :>> ", item);
});
}
});
【问题讨论】:
标签: javascript arrays loops foreach