It's creating an array of arrays. That's not quite the same as a multi-dimensional array, but it serves a similar purpose.
You can get the value 3, for instance, by doing this:
console.log(hanoi_peg[0][2]);
Normally you'd use array literal notation instead:
var hanoi_peg = [
[ 5, 4, 3, 2, 1, 0 ],
[ -1, -1, -1, -1, -1, -1 ],
[ -1, -1, -1, -1, -1, -1 ]
];
The difference between an array of arrays and a multi-dimensional array is that an array of arrays isn't stored in a single contiguous block of memory, and as a result can be jagged; the arrays in the second level don't all have to have the same number of elements. For instance, this is perfectly valid:
var a = [
[1, 2, 3, 4, 5],
[1, 2, 3],
[1, 2, 3, 4, 5, 6]
];
In a true multi-dimensional array, there's one contiguous block of memory (in effect, one big single-dimensional array) and the compiler/runtime just does math on the indexes to find the right slot. For instance, a true 5x5 multi-dimensional array would be a single contiguous set of 25 slots, and when you asked for the entry at [2][4]
, the compiler/runtime would turn that into [(2*5)+4]
and return the contents of slot index 14.
But with an array of arrays, [2][4]
is two different operations: First, get the entry at [2]
, which is a reference to an array; then get the entry at [4]
from that array.