async function apiRequest(id) {
let res = await fetch(`https://jsonplaceholder.typicode.com/todos/${id}`);
let finalRes = await res.json();
return finalRes;
}
let array = [];
async function main() {
for (let i = 1; i <= 5; i++) {
let res = await apiRequest(i);
array.push(res);
}
}
console.log(array); // I can see the out put in the console
array.forEach((element) => {
console.log(element); // but no out put is shown in the console
});
main();
Why can't I see output when I iterate through the array? When I print the array it shows the output and prints all elements. But in forEach block nothing is printed.