var score = 0; var arr = [1,2,3]; function draw(){ score+=1; console.log(score); if(score < arr.length) requestAnimationFrame(draw); } function init(){ requestAnimationFrame(draw); } init();