Answers for "js delayed loop"

4

how to delay iterations in javascript

var i = 1;                  //  set your counter to 1

function myLoop() {         //  create a loop function
  setTimeout(function() {   //  call a 3s setTimeout when the loop is called
    console.log('hello');   //  your code here
    i++;                    //  increment the counter
    if (i < 10) {           //  if the counter < 10, call the loop function
      myLoop();             //  ..  again which will trigger another 
    }                       //  ..  setTimeout()
  }, 3000)
}

myLoop();                   //  start the loop
Posted by: Guest on October-09-2020
1

delayed in js

setTimeout(function(){ alert("After 5 seconds!"); }, 5000);
Posted by: Guest on April-24-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language