Skip to content

Instantly share code, notes, and snippets.

@ReinierC
Last active January 5, 2018 15:38
Show Gist options
  • Save ReinierC/df9296cee51ece317cbb5805980e03d3 to your computer and use it in GitHub Desktop.
Save ReinierC/df9296cee51ece317cbb5805980e03d3 to your computer and use it in GitHub Desktop.

RC Logo

Nested loops & 2-dimensional arrays

Uses nested loops to print data from a 2-dimensional array.

Sample array:

var a = [[4, 2, 0], [8, 11, 9], [7, 0, 7], [7, 4, 28], [3, 10, 26]];

Output:

"row 0" "4" "2" "0" "row 1" “8” “11” “9” … etc

var a2dArray = [
[4, 2, 0],
[8, 11, 9],
[7, 0, 7],
[7, 4, 28],
[3, 10, 26]
];
for(i=0; i<a2dArray.length; i++){
var row2dArray = a2dArray[i];
alert("row " + i);
for(j=0; j<row2dArray.length; j++){
alert(row2dArray[j]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment