How to exit from setInterval

javascript, setinterval

Solution

Use clearInterval:

var refreshId = setInterval(function() {
  var properID = CheckReload();
  if (properID > 0) {
    clearInterval(refreshId);
  }
}, 10000);

Problem

I need to exit from a running interval if the conditions are correct: ``` var refreshId = setInterval(function() { var properID = CheckReload(); if (properID > 0) { <--- exit from the loop---> } }, 10000); ```

Original source