JavaScript berhenti setInterval
var myInterval = setInterval(function(){console.log("mmk")}, 2000);
clearInterval(myInterval); //stop that interval
Grepper
var myInterval = setInterval(function(){console.log("mmk")}, 2000);
clearInterval(myInterval); //stop that interval
let myVar = setInterval(() => {console.log('bop'), 1000);
clearInterval(myVar);
// program to stop the setInterval() method after five times
let count = 0;
// function creation
let interval = setInterval(function(){
// increasing the count by 1
count += 1;
// when count equals to 5, stop the function
if(count === 5){
clearInterval(interval);
}
// display the current time
let dateTime= new Date();
let time = dateTime.toLocaleTimeString();
console.log(time);
}, 2000);
// clearinterval javascript
let intervalID = setTimeout(()=>{
// some code
})
clearInterval(intervalID)