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
1.4m articles
1.4m replys
5 comments
57.0k users