Categories
JavaScript Answers

How to increment or decrement for loop by more than one with JavaScript?

Spread the love

Sometimes, we want to increment or decrement for loop by more than one with JavaScript.

In this article, we’ll look at how to increment or decrement for loop by more than one with JavaScript.

How to increment or decrement for loop by more than one with JavaScript?

To increment or decrement for loop by more than one with JavaScript, we can increment with += or decrement with -=.

For instance, we write

for (let i = 0; i < myVar.length; i += 3) {
  //...
}

to increment i by 3 with i += 3.

Or we write

for (let i = myVar.length - 1; i >= 0; i -= 3) {
  //...
}

to decrement i by 3 with i -= 3.

Conclusion

To increment or decrement for loop by more than one with JavaScript, we can increment with += or decrement with -=.

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 *