My code is :
for (let i = 0; i <= 5; i++) {
delay(i);
}
function delay(i) {
setTimeout(() => console.log(`${i} is the number`), 2000);
}
The output i am getting after 2 second 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
They all print together immediately after 2 second , while I want each of them to print after 2 second for eg :
0 is the number
(after 2 second)
1 is the number
(after 2 second)
2 is the number .....
Is there any way to make it work? Thank you!!