A.k.a. arrays of arrays
const ss = [ 'foo', 'bar', 'baz' ]; // array of strings
const ns = [ 1, 2, 3 ]; // array of nummers
Well …
const grid = [ [ 1, 2 ], [ 3, 4 ] ];
An array of arrays
const ticTacToe = [
[ 'X', 'O', 'O' ],
[ 'O', 'X', '' ],
[ 'X', '', 'O' ],
];
ticTacToe[0][1] = 'O'
ticTacToe[0][1] ⟹ 'O'
const row = ticTacToe[0]; // zeroth row
for (let c = 0; c < row.length; c++) {
console.log(row[c]); // let's log what's there
}
This is just a regular loop over a 1d array.
const c = 0; // column 0
for (let r = 0; r < ticTacToe.length; r++) {
console.log(ticTacToe[r][c]); // let's log what's there
}
The columns are made up of one element from each row of the 2d array.
for (let r = 0; r < ticTacToe.length; r++) {
for (let c = 0; c < ticTacToe[0].length; c++) {
ticTacToe[r][c] = '';
}
}
Loops through every element of the 2d array, setting it to the empty strincg.