loop every 1 second javascript code example
Example 1: run function every second javascript
setInterval(function(){
//this code runs every second
}, 1000);
Example 2: run for loop every second js
var time = 1;
var interval = setInterval(function() {
if (time <= 3) {
alert(time);
time++;
}
else {
clearInterval(interval);
}
}, 5000);