stop setinterval call javascript

How to Stop SetInterval Call in JavaScript

SetInterval is a useful JavaScript function that allows you to execute commands & functions at specific intervals of time. But how do you stop a setInterval call that is already being executed in JavaScript? In this article, we will learn how to stop setInterval call in JavaScript.

How to Stop SetInterval Call in JavaScript

Here is the syntax of setInterval() function.

setInterval(function_call_or_definition, interval_milliseconds);

It is important to remember that setInterval returns the ID of the interval process on being called. You need to save it in case you want to stop setInterval call later.

var IntervalId = setInterval(fname, 10000);

Once you have the interval ID with you, you can call clearTimeout() function to stop the setInterval call of that interval ID.


Once you have stopped the setInterval call it is advisable not to recall it again, else, in some cases, it may start a new timer.

In this article, we have learnt how to stop setInterval call in JavaScript. You can trigger this by click of a button by calling in its event handler.

Also read:

How to Store File Content in Shell Variable
How to Sort Array of Objects By Multiple Objects
How to Get Position of Element in JavaScript
How to Create Multiline Strings in JavaScript
How to Split String by Character

Leave a Reply

Your email address will not be published. Required fields are marked *