JSFiddle - React, Tailwind, and code Playground
HTML
<input type="button" onclick="clearInterval(timer)" value="stop">
JavaScript
var i = 1
timer = setInterval(function() { alert(i++) }, 2000)
<input type="button" onclick="clearInterval(timer)" value="stop">
var i = 1
timer = setInterval(function() { alert(i++) }, 2000)