Exiting setInterval method in javascript

I have a setInterval () function that is used as follows

setInterval(function(){ if(window.document.drops.isFinished()){ //I want to exit the setInterval() on executing this if } },1000); 

or tell me what the exit method is. (In java we use System.exit (0))

+6
source share
1 answer
  var timerId = setInterval(function(){ if(window.document.drops.isFinished()){ clearInterval(timerId); } },1000); 

If if this is not the last in the function and you want to β€œsplit” the execution, you might also want to add a return; after clearInterval .

+19
source

Source: https://habr.com/ru/post/948856/


All Articles