#Nested for loop not functioning (Beginner)

4 messages · Page 1 of 1 (latest)

real saddle
#

Here is the code

coral thorn
#

It looks like you want to loop over 2 nested arrays, but the arrays are not defined in you example code.
Normally a nested array is sth like
const nested = [[1,2,3], ['a','b','c']]

#

/run

const nested = [ [ 1, 2, 3 ], [ 'a', 'b', 'c' ] ];
for (let i = 0; i < nested.length; i++) {
    for (let j = 0; j < nested[ i ].length; j++) {
        console.log(`at outer index ${i}, inner index ${j}: ${nested[ i ][ j ]}`);
    }
}```