Call a Javascript function every 5 seconds continuously [duplicate] Ask Question

Call a Javascript function every 5 seconds continuously [duplicate] Ask Question

Possible Duplicate:
Calling a function every 60 seconds

I want to Call a Javascript function every 5 seconds continuously. I have seen the setTimeOut event. Will it be working fine if I want it continuously?

ベストアンサー1

You can use setInterval(), the arguments are the same.

const interval = setInterval(function() {
   // method to be executed;
 }, 5000);

clearInterval(interval); // thanks @Luca D'Amico

おすすめ記事