Timing in JS - multiple setIntervals running at once and starting at the same time?

前端 未结 5 2392
忘了有多久
忘了有多久 2020-12-14 16:53

Let\'s say I have a function:

myFunc = function(number) {
  console.log(\"Booyah! \"+number);
}

And I want it to run on a set interval. Sou

5条回答
  •  半阙折子戏
    2020-12-14 17:15

    You can make something like this.

    arr = Array();
    arr[0] = "hi";
    arr[1] = "bye";
    setTimer0 = setInterval(function(id){
      console.log(arr[id])
    },1000,(0));
    
    setTimer1 = setInterval(function(id){
      console.log(arr[id]);
    },500,(1));
    

    Hope it helps!

提交回复
热议问题