JavaScript clearInterval() method explained
The JavaScript clearInterval() method is a method from the DOM Window object that you can use to stop the function that you execute using the setInterval() method.
For example, the following fnLog() function that runs every 1 second under setInterval() method:
let timer = setInterval(fnLog, 1000);
function fnLog() {
console.log("Function fnLog executed");
}
To stop the fnLog() function above from running forever, you call the clearInterval() method:
clearInterval(timer);
With that, the fnLog() function will stop executing.
Both the browser and Node.js has the clearInterval() method implemented, so you can use the method on both environments.
More JavaScript tutorials
See allJavaScript
Sort Keys in Map Using JavaScript
Dec 11, 2023
JavaScript
Get Element by Data Attribute Using JavaScript
Dec 8, 2023
JavaScript
Convert Milliseconds to Hours Minutes Seconds in JavaScript
Dec 6, 2023
JavaScript
JavaScript Get the Index of Max Value in Array
Nov 16, 2023
JavaScript
JavaScript Check if Value is an Object
Nov 15, 2023