Categories
JavaScript Answers

How to do something N times with JavaScript?

Spread the love

Sometimes, we want to do something N times with JavaScript.

In this article, we’ll look at how to do something N times with JavaScript.

How to do something N times with JavaScript?

To do something N times with JavaScript, we use a for loop.

For instance, we write

const times = 10;

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

to use a for loop to loop i from 0 to 9.

We use i++ to increment i by 1 after each iteration.

And we call doSomething during each iteration.

Conclusion

To do something N times with JavaScript, we use a for loop.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *