Answers for "wait specific time javascript"

103

js wait 1 second

function delay(time) {
  return new Promise(resolve => setTimeout(resolve, time));
}

delay(1000).then(() => console.log('ran after 1 second1 passed'));
Posted by: Guest on October-25-2021
6

wait for time javascript

//code before the pause
setTimeout(function(){
    //do what you need here
}, 2000);
Posted by: Guest on November-28-2019
0

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
Posted by: Guest on January-25-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language