Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

GodziLaravel's avatar

is there any short code to repeat a function n times ?

Hello ,

To repeat getCompetenceLogs() function 3 times I use this bellow ,

for (let i = 0; i < 3; i++)this.getCompetenceLogs();

I'm wondering if there is in javascript another way to repeat function N times ?

thanks

0 likes
1 reply
Talinon's avatar
Talinon
Best Answer
Level 51

@mostafalaravel

Instead of calling the function repeatedly, you could consider changing the function to accept an argument for the number of repetitions.

this.getCompetenceLogs(3);

function getCompetenceLogs(times = 1)
{

    for (i = 0; i < times; i++)
    {
         ...
    }

}

Please or to participate in this conversation.