Is there any way to call a function periodically in JavaScript?
The setInterval() method, repeatedly calls a function or executes a code snippet, with a fixed time delay between each call. It returns an interval ID which uniquely identifies the interval, so you can remove it later by calling clearInterval().
setInterval()
var intervalId = setInterval(function() { alert("Interval reached every 5s") }, 5000); // You can clear a periodic function by uncommenting: // clearInterval(intervalId);
See more @ setInterval() @ MDN Web Docs
2.1m questions
2.1m answers
60 comments
57.0k users