Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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();
Source by flaviocopes.com #
 
PREVIOUS NEXT
Tagged: #settimeout #loop
ADD COMMENT
Topic
Name
8+3 =