JavaScript - - By Sam Deering

JS display and/or stop current setinterval events

Use JavaScript to show current setInterval events. Here we have declared a setInterval() without keeping a reference to the id which is returned from the function call (setInterval() returns an id number for the registered event)

var interval = setInterval(function() {
}, 1000);

It you can see it assigns a random number as the id for the event. Then when we clear the interval it uses that id.


We can simply do a loop to find the id of the event to stop all setInterval() events that are running.

for(i=0; i<100; i++)

I’m pretty sure this will also work for setTimeout() and clearTimeout();