let stars = ' '; If you initialize the string with a space in it, with the plan to concatenate stars, then the result will be * ** *** and so on, instead of * ** *** which, while only a small difference, is technically wrong. for (let col = 0 ; col < row.length; col++){ A couple things heโ€ฆ Answer from colinthornton on forum.freecodecamp.org
๐ŸŒ
Softuni
js-book.softuni.org โ€บ chapter-06-nested-loops.html
6.1. Nested Loops ยท Programming Basics with JavaScript
This is repeated until the variable of the outer loop meets the condition to end the loop. Here is an example that illustrates nested loops.
Discussions

Nested For Loops
Hey all. First time poster on FCC. I tried algorithm scripting with high difficulties like others. So I wanted to take a step back and look at nested for loops to increase my understanding. Iโ€™m attempted to printout a soโ€ฆ More on forum.freecodecamp.org
๐ŸŒ forum.freecodecamp.org
1
0
July 22, 2020
Understanding nested for loops in javascript - Stack Overflow
I'm learning JavaScript at the moment on freecodecamp and they have an example for nested for loops in one of their excercises: More on stackoverflow.com
๐ŸŒ stackoverflow.com
Javascript "Nested Loops" - exercise 6
Hey all, first of all thanks for looking at my post, hopefully you can answer my question. Exercise Link: https://www.codecademy.com/courses/introduction-to-javascript/lessons/loops/exercises/for-loops-iii Please see mโ€ฆ More on discuss.codecademy.com
๐ŸŒ discuss.codecademy.com
0
0
March 18, 2020
Understanding Nested For Loops in JavaScript Arrays - LambdaTest Community
Iโ€™m currently learning JavaScript on FreeCodeCamp, and I encountered an example involving nested for loops in JavaScript in one of their exercises: var arr = [[1, 2], [3, 4], [5, 6]]; for (var i = 0; i More on community.lambdatest.com
๐ŸŒ community.lambdatest.com
0
October 24, 2024
๐ŸŒ
Softuni
js-book.softuni.org โ€บ chapter-06-nested-loops-exam-problems.html
6.2. Nested Loops โ€“ Exam Problems ยท Programming Basics with JavaScript
The lower part of the figure, in which the width of the sign decreases, can be done by creating a loop, that iterates n number of times. The structure of a row should have a beginning . + \\, middle part _ and an end // + .. The number of the dots in the first loop iteration has to be 0 and ...
๐ŸŒ
EDUCBA
educba.com โ€บ home โ€บ software development โ€บ software development tutorials โ€บ javascript tutorial โ€บ nested loop in javascript
Nested Loop in JavaScript | Guide to Nested Loop - Flowchart & Examples
June 28, 2023 - If it is true, then the inner loop is executed again, and these steps will be repeated until the condition in the outer loop is true. JavaScript supports the nested loop feature, where a loop is present inside another loop.
Call ย  +917738666252
Address ย  Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
๐ŸŒ
W3Resource
w3resource.com โ€บ javascript-exercises โ€บ javascript-conditional-statements-and-loops-exercises.php
JavaScript conditional statements and loops - Exercises, Practice, Solution - w3resource
July 10, 2025 - Write a JavaScript program that iterates integers from 1 to 100. But for multiples of three print "Fizz" instead of the number and for multiples of five print "Buzz". For numbers multiples of both three and five print "FizzBuzz". ... "Starting with any positive integer, replace the number by the sum of the squares of its digits, and repeat the process until the number equals 1 (where it will stay), or it loops endlessly in a cycle which does not include 1.
๐ŸŒ
AlgoCademy
algocademy.com โ€บ link
Nested Loops in JavaScript | AlgoCademy
Learn "Nested Loops in JavaScript" with our free interactive tutorial. Master this essential concept with step-by-step examples and practice exercises.
Find elsewhere
๐ŸŒ
Scientech Easy
scientecheasy.com โ€บ home โ€บ blog โ€บ nested for loops in javascript
Nested For Loops in JavaScript - Scientech Easy
August 14, 2025 - Learn nested for loops in JavaScript, basic syntax, example programs based star, numbers, and alphabet design patters using nested for loops
๐ŸŒ
Basescripts
basescripts.com โ€บ mastering-javascript-nested-loops-coding-exercises-and-quiz-questions-test-your-knowledge
Mastering JavaScript Nested Loops Coding Exercises and Quiz questions Test your Knowledge โ€“ Coding Help Tips Resources Tutorials
December 5, 2023 - Understand the structure of nested loops. Utilize them for various tasks: printing patterns, handling arrays, and more. Be mindful of performance considerations. ... Nested loops are loops within loops, allowing for more complex iterations through ...
๐ŸŒ
Khan Academy
khanacademy.org โ€บ computing โ€บ computer-programming โ€บ programming โ€บ looping โ€บ pt โ€บ nested-for-loops
Nested For Loops | Looping | Intro to JS
Learn for free about math, art, computer programming, economics, physics, chemistry, biology, medicine, finance, history, and more. Khan Academy is a nonprofit with the mission of providing a free, world-class education for anyone, anywhere.
Top answer
1 of 7
21
var arr = [[1,2], [3,4], [5,6]];

This is an array of arrays. It is a little bit easier to read like this:

var arr = [
            [1,2],
            [3,4],
            [5,6]
          ];

That makes it a little bit easier to see that you have an array of 3 arrays. The outer 'for' will loop through each of 1st level arrays. So the very first outer for loop when i=0 you are going to grab the first inner array [1,2]:

for (var i=0; i < arr.length; i++) {
    //First time through i=0 so arr[i]=[1,2];
}

In the inner loop you are going to loop through each of the 3 inner arrays one at a time.

for (var j=0; j < arr[i].length; j++) {
    //Handle inner array.
}

This argument grabs the length of the inner array:

arr[i].length

So on your first time through the outer loop i=0 and arr[i] is going to equal [1,2] because you are grabbing the 0th element. Remember, arrays elements are always counted starting at 0, not 1.

Finally you are printing out the results with:

console.log(arr[i][j]);

The first time through you can break it down a little. i=0 and j=0. arr[0][0] which translates as grab the first element from the outer array and then the first element from the first inner array. In this case it is '1':

[
    [1,2], <-- 0
    [3,4], <-- 1
    [5,6]  <-- 2
];

The code will loop through the first first set [1,2], then the second [3,4], and so on.

2 of 7
9

The double for loop you have above works like so:

 var arr = [[1,2], [3,4], [5,6]];

 for (var i=0; i < arr.length; i++) {
  // i = 0, then we loop below:
  for (var j=0; j < arr[i].length; j++) {
    //here we loop through the array which is in the main array
    //in the first case, i = 0, j = 1, then we loop again, i = 0, j = 1
    console.log(arr[i][j]);
    //after we finish the stuff in the 'j' loop we go back to the 'i' loop 
    //and here i = 1, then we go down again, i, remains at 1, and j = 0, then j = 1
    //....rinse and repeat, 
  }
}

In plain english:

We grab the first element in the main array, which is an array itself, we loop through that, and log at each index, this is terminated by our length condition in the second loop. We then move to to the next index of the main array, which is an array itself.... and so on, until we reach the end of the main array

To access and index in the main array, we need to use array[i] - that index holds an array - so to go INTO that array, we need to use array[i][j]

Hope that makes sense!

๐ŸŒ
Codecademy Forums
discuss.codecademy.com โ€บ get help โ€บ javascript
Javascript "Nested Loops" - exercise 6 - JavaScript - Codecademy Forums
March 18, 2020 - Hey all, first of all thanks for looking at my post, hopefully you can answer my question. Exercise Link: https://www.codecademy.com/courses/introduction-to-javascript/lessons/loops/exercises/for-loops-iii Please see my code below. I can can log the resulant array to the console, yet I get a โ€˜Did you write a nested for loop?โ€™ error. let bobsFollowers = ['Ash','Barry','Calum','Denny']; let tinasFollowers = ['Ash','Denny','Rob']; let mutualFollowers = []; for (i = 0 ; i
๐ŸŒ
Teaching-materials
teaching-materials.org โ€บ javascript โ€บ exercises โ€บ forloops
JavaScript 1: for loops
Write a for loop that will iterate from 0 to 10. For each iteration of the for loop, it will multiply the number by 9 and log the result (e.g. "2 * 9 = 18"). Bonus: Use a nested for loop to show the tables for every multiplier from 1 to 10 (100 results total).
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ nesting-for-loops-in-javascript
Nesting For Loops in JavaScript
June 2, 2020 - If you're having trouble understanding freeCodeCamp's Nesting For Loops challenge, don't worry. We got your back. In this problem you have to complete the multiplyAll() function, and takes a multi-dimensional array as an argument. Remember that a mul...
๐ŸŒ
Coding Rooms
codingrooms.com โ€บ blog โ€บ nested-loops-javascript
Nested Loops JavaScript
October 6, 2020 - The inner loop prints the individual digits while the outer loop determines how many times this task is repeated. Try changing counter < 4 to counter < 1. The numbers 1 through 3 should only be printed once if this change is made.
๐ŸŒ
LinkedIn
linkedin.com โ€บ pulse โ€บ mastering-javascript-nested-loops-coding-exercises-quiz-svekis--g3ngc
Mastering JavaScript Nested Loops Coding Exercises and Quiz questions Test your Knowledge
December 5, 2023 - Get PDF guide with Exercises and Quiz questions https://basescripts.com/mastering-javascript-nested-loops-coding-exercises-and-quiz-questions-test-your-knowledge Nested Loops in JavaScript Nested loops are loops within loops, allowing for more complex iterations through data structures like arrays o
๐ŸŒ
LambdaTest Community
community.lambdatest.com โ€บ general discussions
Understanding Nested For Loops in JavaScript Arrays - LambdaTest Community
October 24, 2024 - Iโ€™m currently learning JavaScript on FreeCodeCamp, and I encountered an example involving nested for loops in JavaScript in one of their exercises: var arr = [[1, 2], [3, 4], [5, 6]]; for (var i = 0; i < arr.length; i++โ€ฆ
๐ŸŒ
W3Schools
w3schools.com โ€บ jsref โ€บ jsref_for.asp
JavaScript for Statement
A nested loop (a loop inside a loop): let text = ""; for (let = 0; i < 3; i++) { text += i + "<br>"; for (let j = 10; j < 15; j++) { text += j + "<br>"; } } Try it Yourself ยป ยท for is an ECMAScript1 (JavaScript 1997) feature.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ nesting-for-loops-in-javascript
Nesting For Loops in JavaScript - GeeksforGeeks
Exercise ยท Last Updated : 5 Aug, ... or performing complex tasks. It involves placing one loop inside another, where the outer loop executes for each iteration of the inner loop....
Published ย  August 5, 2025