LoginSignup
2
2

More than 5 years have passed since last update.

JavaScriptで一定時間ごとに実行する処理を短く書く

Last updated at Posted at 2017-05-27

コード

(function loop() {
  // 処理を書く
  setTimeout(loop,1000);
})();

※loopはなんでもいい

カウントする

var i = 0;

(function loop() {
  i++;
  console.log(i);
  setTimeout(loop,1000);
})();

繰り返し回数を指定する

var i = 0;
var time = 10;

(function loop() {
    i++;
    console.log(i);
    if (i<10) {setTimeout(loop,1000);}
})();
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2