Basic JavaScript - Nesting For Loops

Tell us what’s happening:

Describe your issue in detail here.
Hello everyone,

Can i use nested loop to write

1 Outer loop and two inner loops? To make it clear, see the code below.

What i want to get from doing this is:

Comparing the elements of the two array, i want to be able to see if some element exist on the other array. I need to do it to complete some challenge, that’s why i can’t just type
Array1.indexOf(Array2[index]);
Because i have to create a code that any arguments can use.


const both = [[0, 1, 2, 3, 4],[0, 1, 2, 3]];

for (let B = 0; B < both.length; B = B + 1)
 { for (let R = 0; R < both[B].length; R = R + 1){
console.log(B, both[B]); }  //
for (let S = 0; S < both[B].length; S = S + 1) {
console.log(S, “Yes”); }
Console.log(B, “END”); }; 

// for (let R…etc) refer to both[0]
// for (let S…etc) refer to both[1]

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.6 Safari/605.1.15

Challenge Information:

Basic JavaScript - Nesting For Loops

  • conceptually speaking yes you can but for this step you can just do it with two loops, if im not wrong!!
  • have you tried looking into this given example and understand it clearly?
for (let i = 0; i < arr.length; i++) {
  for (let j = 0; j < arr[i].length; j++) {
    console.log(arr[i][j]);
  }
}

happy coding :slight_smile:

1 Like

I do get nested loop

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.