Removing intervals

suggest change

window.setInterval() returns an IntervalID, which can be used to stop that interval from continuing to run. To do this, store the return value of window.setInterval() in a variable and call clearInterval() with that variable as the only argument:

function waitFunc(){
    console.log("This will be logged every 5 seconds");
}    

const interval = window.setInterval(waitFunc,5000);

window.setTimeout(function(){
    clearInterval(interval);
},32000);

setInterval is available in browsers and in Node. The delay is a minimum. With exact timers the callback runs at 5, 10, 15, 20, 25, and 30 seconds, six times, and the 32-second timeout stops it before another run. A delayed timer can change that count.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents