Normally, I’d set the interval to a variable and then clear it like var the_int = setInterval(); clearInterval(the_int);
but for my code to work I put it in an
// Initiate set interval and assign it to intervalListener
var intervalListener = self.setInterval(function () {someProcess()}, 1000);
function someProcess() {
console.log('someProcess() has been called');
// If some condition is true clear the interval
if (stopIntervalIsTrue) {
window.clearInterval(intervalListener);
}
}