1const interval = setInterval(function() {
2 // method to be executed;
3 }, 5000);
4
5clearInterval(interval); // thanks @Luca D'Amico
6
1window.setInterval(function() {
2 // do stuff
3}, 1000); // 1000 milliseconds (1 second)
1// your function
2function myTimer() {
3 console.log(' each 1 second...');
4}
5
6var myVar = setInterval(myTimer, 1000); //setting the loop with time interval
7
8clearInterval(myVar); //call this line to stop the loop
9