1function timeout() {
2 setTimeout(function () {
3 // Do Something Here
4 // Then recall the parent function to
5 // create a recursive loop.
6 timeout();
7 }, 1000);
8}
1var array = [1, 2, 3, 4, 5]for(var i = 0; i < array.length; i++) { setTimeout(() => { console.log(array[i]) }, 1000);} // i = 5
1//you can leave the sleep constant
2const sleep = (milliseconds) => {
3 return new Promise(resolve => setTimeout(resolve, milliseconds))
4}
5
6const doSomething = async () => {
7 for (/*for loop statements here*/) {
8 //code before sleep goes here, just change the time below in milliseconds
9 await sleep(1000)
10 //code after sleep goes here
11 }
12 }
13doSomething();