Use the += assignment operator:

for (var i = 0; i < myVar.length; i += 3) {

Technically, you can place any expression you'd like in the final expression of the for loop, but it is typically used to update the counter variable.

For more information about each step of the for loop, check out the MDN article.

Answer from Andrew Whitaker on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Operators › Increment
Increment (++) - JavaScript - MDN Web Docs - Mozilla
The increment (++) operator increments (adds one to) its operand and returns the value before or after the increment, depending on where the operator is placed.
Discussions

javascript - JS loop increment each value by 2 - Stack Overflow
Is there a way to increment each result of a loop by 2 each time? So it should increase the values by 2, then 4, then 6... So if the first result is 2, it should be 2*2=4 But the second result sho... More on stackoverflow.com
🌐 stackoverflow.com
Increment and decrement
The first line sets the value to 0 (obviously). Line 2 says "Return the value of counter, then add 1 to it" Line 3 says "Add 1 to the value of counter, then return the value of counter" So it becomes: 0 + 1 + 1 = 2 Notice the difference between the two. In the first line, counter's value is returned FIRST, then the increment occurs. In the second line, the value is incremented first. Try this: let counter = 0; console.log(counter++); // the output will be 0! counter = 0; console.log(++counter); // the output will be 1! This works because if the "++" is placed after the variable, the variable value is returned before the increment is applied. On the other hand, placing it before the variable increments the variable before it is returned. You don't see it in your code because you're not examining the value at each step. If you did this: let counter=0; console.log(counter++); console.log(++counter); alert(counter); Your output will be 0, then 2, and the alert will be 2. More on reddit.com
🌐 r/learnjavascript
13
2
July 1, 2024
Basic JavaScript: Increment a Number with JavaScript
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read · See this post to find the backtick on your keyboard. More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
0
October 9, 2018
Question about incrementation when looping.
In a for(initialization; condition; increment) loop, the "initialization" code is always executed, before anything else happens. Then the loop begins. The loop is equivalent to a while loop in that there is a "condition", and this condition is tested before every iteration -- including the first iteration. (This means your for or while loop might never execute the body of the loop, which is correct.) At the end of the loop body, or the beginning of every iteration except the first, the "increment" part is executed. Thus, the increment does not run before the first time, but does run every other time. The use of a continue statement to advance to the next iteration through the loop will run the increment part. Simplified, it looks like this: initialization part goto condition top-of-loop: body of loop /* continue stmt */ goto end-of-body /* break stmt */ goto break end-of-body: increment part condition: evaluate condition part if truthy goto top-of-loop break: whatever code is after your for loop Note here that truthy in C has a particular meaning: non-zero. Any "condition" type test will compare the result of a contained expression against zero. A zero is considered false, and any value other than zero is considered true. "1" is true. "1000000" is true. "6.02E+23" is true. "&main" is true. "NaN" is true. "Inf" is true. "-Inf" is true. I honestly do not know if -0 is true or not, on a sign+magnitude CPU. Yes, there is a boolean type. But the boolean type was added much, much, much later. Before there was a boolean type, everything was int, and so the foundation of the language assumes that the truthiness of int value: 0 vs. non-0, drives everything. More on reddit.com
🌐 r/cprogramming
12
11
February 7, 2023
🌐
Delft Stack
delftstack.com › home › howto › javascript › javascript increment by 2
Increment by 2 in for Loop in JavaScript | Delft Stack
October 12, 2023 - By default, the condition always evaluates to true. The code/statement will only be executed if this expression evaluates true. If the expression evaluates to false, execution skips the code/statement written inside the block. The $final-expression is an expression to be evaluated at the end of each loop iteration. This expression is executed before the next evaluation of the condition. It is generally used to increment or decrement the counter variable.
🌐
Linux Hint
linuxhint.com › increment-by-2-in-for-loop-in-javascript
How to Increment by 2 in for Loop in JavaScript
November 11, 2022 - Linux Hint LLC, [email protected] 1210 Kelly Park Circle, Morgan Hill, CA 95037 Privacy Policy and Terms of Use
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript for loop increment | final expression
JavaScript for loop increment example | Final Expression - EyeHunts
September 14, 2021 - Here is an example using an Array, the same way you can do for increments of 3,4 and so on. <!DOCTYPE html> <html> <body> <script> var myVar = [1,2,3,4,5,6,7,8,9,10] for (var i = 0; i < myVar.length; i += 2) { console.log(myVar[i]); } </script> </body> </html>
🌐
Medium
medium.com › @ryan_forrester_ › incrementing-values-in-javascript-how-to-guide-ea389b4ea9fa
Incrementing Values in JavaScript (How to Guide) | by ryan | Medium
September 12, 2024 - The simplest way to increment a variable is by using the increment operator (++). This operator increases the value of a variable by one. let counter = 0; counter++; console.log(counter); // Output: 1 · You can also use the addition assignment ...
Find elsewhere
🌐
Codecademy
codecademy.com › forum_questions › 508fe06f900ba10200002d7f
the for loop increment | Codecademy
As @Alex J explained above, the ... + 2, or counter = counter -5. Increment always means ‘add to’, decrement always means ‘subtract from’. ... In this SQL course, you'll learn how to manage large datasets and analyze real data using the standard data management language. Beginner Friendly.Beginner Friendly4 Lessons4 Lessons ... Learn how to use JavaScript — a powerful ...
🌐
CodeBurst
codeburst.io › javascript-increment-and-decrement-8c223858d5ed
JavaScript Increment ++ and Decrement -- | by Brandon Morelli | codeburst
December 12, 2017 - // Incrementlet a = 1;console.log(++a); // 2 console.log(a); // 2// Decrementlet b = 1;console.log(--b); // 0 console.log(b); // 0
🌐
Reddit
reddit.com › r/learnjavascript › increment and decrement
r/learnjavascript on Reddit: Increment and decrement
July 1, 2024 -

Hi everyone,

I’m new to JavaScript and I was learning about increment and decrement. I am confused with the following code:

let counter = 0; counter++; ++counter; alert(counter);

Why is the output 2? I would assume the second line would result to 0, and the third line would result to 1 with a final return of 1?

Thank you in advance. I know this is a silly question :(

🌐
TechOnTheNet
techonthenet.com › js › for_loop.php
JavaScript: For Loop
For example, you could use counter++ to increment the counter by 1 or you could use counter-- to decrement the counter by 1. ... The statements of code to execute each pass through the loop. You would use a for loop when you want to execute the loop body a fixed number of times. See also the break statement to exit from the for loop early. Let's look at an example that shows how to use a for loop in JavaScript.
🌐
freeCodeCamp
forum.freecodecamp.org › javascript
Basic JavaScript: Increment a Number with JavaScript - JavaScript - The freeCodeCamp Forum
October 9, 2018 - var myVar = 87; // Only change code below this line var myVar = myVar ++; var myVar = 88; but i keep getting this error message : / / running tests myVar = myVar + 1; should be changed // tests completed please h…
🌐
W3Schools
w3schools.com › js › js_operators.asp
JavaScript Operators
// Assign the value 5 to x let x = 5; // Assign the value 2 to y let y = 2; // Assign the value x + y to z: let z = x + y; Try it Yourself »
🌐
Tutorial Gateway
tutorialgateway.org › increment-and-decrement-operators-in-javascript
Increment and Decrement Operators in JavaScript
March 28, 2025 - Let’s explore the JavaScript prefix and postfix. ++i (Pre increment): It will increment the value of i even before assigning it to the variable i. i++ (Post-increment): The operator returns the variable value first (i.e, i value) then only i value will incremented by 1.
🌐
Launch School
launchschool.com › books › javascript › read › loops_iterating
Loops in JavaScript - performing repeated operations on a data set
Since counter's initial value is ... Inside the block, we output counter's value, then increment it by 1. After the first block iteration, JavaScript re-evaluates the conditional expression. This time, counter is 2, which is still less than or equal to 1000; thus, the block ...
🌐
AlgoCademy
algocademy.com › link
Increment And Decrement Operators in JavaScript | AlgoCademy
There is also one such operator for decreasing the value of a variable by 1. ... In the examples above, we have used these two operators in their postfix form, with operator (++) after operand (number) such as number++. If used postfix, the increment operator increments and returns the value before incrementing:
🌐
TutorialsPoint
tutorialspoint.com › How-to-increment-one-or-more-counters-with-JavaScript
How to increment one or more counters with JavaScript?
In this tutorial, we learned three ways to increment one or more counters with JavaScript. We used loop iterations, events, and the setInterval() method to increment a counter.