Pass it to the function clearInterval and you're safe: Code: Always store the returned number of setInterval in a variable, so that you can stop the interval later on: const intervalID = setInterval(f, 1000); // Some code. clearInterval(intervalID); (Think of this number as the ID of a setInterval. More @Wikipedia
Hover over any link to get a description of the article. Please note that search keywords are sometimes hidden within the full article and don't appear in the description or title.