Ask coding questions

← Back to all posts
Do somthing every second
LukeShomper (49)

How would I make a script do an action every second?

Answered by mwilki7 (1078) [earned 5 cycles]
View Answer
mwilki7 (1078)
    // your code here to be done every second
}, 1000); // 1000 milliseconds = 1 second

More examples here

If you want to stop it do:

var my_interval = setInterval(function() {
     // code here
}, 1000);


setTimeout is basically the same thing if you want a setInterval that only does it once.