I'm missing a simple syntax rule, so maybe you can point it out to me.
I have an object defined as the following...
var board = {
//this data structure was heavily discussed with Lydia Brothers. its current form is due to her help
state: {
flipped: true,
ballWasDroppedLastMove: false,
topPlace: 0,
bottomPlace: 0,
top: [[1,2,3,4,5,6],[7,8,9,10,11,99],[12,13,14,15,99,99],[16,17,18,99,99,99],[19,20,99,99,99,99],[21,99,99,99,99,99]],
bottom: [[0,0,0,0,0,0],[0,0,0,0,0,99], [0,0,0,0,99,99], [0,0,0,99,99,99], [0,0,99,99,99,99], [0,99,99,99,99,99]],
}, ...
The I do some operations on the object -- in particular I'm interested in board.state.top
.
When I print board.state.top
to the console I get something like the following picture...
I want to access the values 12,11,0,0,99,99
.
My experience from other languages tells me I should do something like this...
for (i=0; i<6; i++){
console.log(pboard.state.top[i])
}
...and that's exactly how I got the above image. I tried something like board.state.top[i][j]
(adding the extra dimension) but that prints the values 0,0,0,0,99,99
How do I access those elements?
As suggested below, I tried the following (to no extent)...
var i;
var j;
for (i=0; i<6; i++){
row = pboard.state.top[i];
row.forEach(element => {console.log(element);});
// for (j=0; j<6; j++){
// console.log(top[j])
// }
}