Javascript run a function inside a loop every x iterations

前端 未结 5 1452
借酒劲吻你
借酒劲吻你 2020-12-07 03:30

I have a variable of unknown value, it will be an integer. For this sake, lets say var a = 3;

I have a function that is called continuously:

<         


        
5条回答
  •  情话喂你
    2020-12-07 04:15

    Create a second variable which keeps hold of the current count, then wrap the call you only want every third iteration with

    if(counter % a == 0) {
        //code you want called
    }
    

提交回复
热议问题