Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

wait for 1 second in loop in javascript

(function myLoop(i) {
  setTimeout(function() {
    console.log('hello'); //  your code here                
    if (--i) myLoop(i);   //  decrement i and call myLoop again if i > 0
  }, 3000)
})(10);                   //  pass the number of iterations as an argument
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #wait #loop #javascript
ADD COMMENT
Topic
Name
8+5 =