I want to iterate some page URLs, stored in an array, and retrieve them to do an operation over their html file. Since I need to store a result from said operation for each page to use them the next time I call the function, I want to pass the index (i) in the onResponse call so that it can assign the result to its proper place in the array. But instead of using the i value from the respective i-th iteration, this function call uses pages.length (i's last value). I know why this happens, but I don't know what would be a good solution. Any help here?
async function checkPages(){
const dateObj = new Date();
console.log(pages.length)
console.log(`Time: ${dateObj.toTimeString()}\n`);
for (var i = 0; i < pages.length; i++){
axios.get(pages[i], { httpsAgent })
.then(response => onResponse(response, i)
)
.catch(function (error) {
onError(error)
});
}