How would I stop this loop? The loop is necessary, I'm just not sure how I stop it when I need to.
setInterval(function(){
console.log("Loop running");
}, 6000);
How would I stop this loop? The loop is necessary, I'm just not sure how I stop it when I need to.
setInterval(function(){
console.log("Loop running");
}, 6000);
You can use clearInterval(intervalId)
let intervalId = setInterval(function(){
console.log("Loop running");
}, 6000);
// on some action
clearInterval(intervalId);