Here is the code I'm using:
for (let i = 0; i <= 5; i++) {
delay(i);
}
function delay(i) {
setTimeout(() => console.log(`${i} is the number`), 2000);
}
The output I'm currently getting after 2 seconds is:
0 is the number
1 is the number
2 is the number
3 is the number
4 is the number
5 is the number
All of them print together immediately after 2 seconds, but I want each one to print after 2 seconds, like this:
0 is the number
(after 2 seconds)
1 is the number
(after 2 seconds)
2 is the number .....
Is there a way to achieve this desired delay in printing the numbers? Thank you!!