For loop with counter:
for(let i = page; i < numPages + 1; i++){
const fn = async() => {
const res = await xxx(i);
console.log("page", i);
return res;
}
promises.push(fn);
}
While loop with same type of counter:
while(page < numPages + 1){
page++;
const fn = async() => {
const res = await xxx(page);
console.log("page", page);
return res;
}
promises.push(fn);
}
They are producing different results.
For is display the counter normally.
But while is displaying the last value every time.
why?