Correct the code to print 1 to 10 numbers without removing setTimeout in for loop using ES5 for (var i=0; i<10; i++) { setTimeout(() => console.log(i)); } code example
Example: settimeout inside loop
//you can leave the sleep constant
const sleep = (milliseconds) => {
return new Promise(resolve => setTimeout(resolve, milliseconds))
}
const doSomething = async () => {
for (/*for loop statements here*/) {
//code before sleep goes here, just change the time below in milliseconds
await sleep(1000)
//code after sleep goes here
}
}
doSomething();