looping setTimeout function js code example
Example 1: javascript settimeout loop
function timeout() {
setTimeout(function () {
// Do Something Here
// Then recall the parent function to
// create a recursive loop.
timeout();
}, 1000);
}
Example 2: settimeout in loop javascript
var array = [1, 2, 3, 4, 5]for(var i = 0; i < array.length; i++) { setTimeout(() => { console.log(array[i]) }, 1000);} // i = 5