Last active
October 9, 2017 13:14
-
-
Save rafaelmaeuer/dc78ac15683b0a0f7cad835c72ebdc85 to your computer and use it in GitHub Desktop.
How do I add a delay in a JavaScript loop? - From https://stackoverflow.com/questions/3583724/how-do-i-add-a-delay-in-a-javascript-loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function myLoop (i) { | |
setTimeout(function () { | |
alert('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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment