在这个问题中,我试图遍历从承诺中检索到的对象数组,并且对于数组中的每个对象,我想调用另一个承诺。一旦我调用了所有这些承诺,我想将 DONE 记录到控制台。
我如何知道所有的承诺何时完成?
function myFunction() {
fetch("https://jsonplaceholder.typicode.com/albums").then(first_response => {
first_response.json().then(function(value) {
for (var i = 0; i < value.length; i++) {
fetch("https://jsonplaceholder.typicode.com/users")
.then(second_response => second_response.json())
.then(value => console.log(value))
}
console.log("DONE!!");
});
});
}
myFunction();
.as-console-wrapper { max-height: 100% !important; top: 0; }