Friday, 23 August 2013

How do I use nested For loops to print array values within an array on new lines?

How do I use nested For loops to print array values within an array on new
lines?

I'm trying to get the numbers from these arrays within an array to print
on new lines, but can't figure out how to refer to them in order to print
them to the console. What am I missing here?
var numbers = [
[1,2,3,4,5,6,7],
[8,9,10,11,12,13,14,15,16],
[17,18,19],
[20],
[21,22,23,24,25,26],
[27,28,29,30]
];
for (i=0; i<numbers.length; i++) {
for (j=0; j<numbers[i].length; j++) {
console.log(numbers[i].j); //The problem is with this j here I
suspect...
}
}

No comments:

Post a Comment