var iterationCount = 0; function myTimer(){ if (iterationCount++ < 10){ clearInterval(myTimerIntervalId); }; ... }; var myTimerIntervalId = setInterval(myTimer, 1000);