pause in a loop javascript code example
Example 1: js wait for time
function sleep(milliseconds) {
const start = Date.now();
while (Date.now() - start < milliseconds);
}
console.log("Hello");
sleep(2000);
console.log("World!");
Example 2: pause javascript
function wait(ms)
{
var d = new Date();
var d2 = null;
do { d2 = new Date(); }
while(d2-d < ms);
}