I've got a 2 dimensional array (I'll call it myArray
). myArray
is full of 10 child arrays, each with 10 "-"s.
function mapInit () {
max_size = 10;
board = [];
map_width = Math.floor((Math.random() * max_size + max_size) / 2);
map_height = Math.floor((Math.random() * max_size + max_size) / 2);
boardsize = { x : map_width, y : map_height }
}
function generateBoard () {
var columns = [];
for (var i = 0; i < map_height; i++) {
columns.push("---");
};
for (var i = 0; i < map_width; i++) {
board.push(columns);
};
}
When I select myArray[x][y]
, it returns the value of the single object in that array: "-". This makes sense because I asked for that individual value.
When I set myArray[x][y] = 1
, it sets all [y] in the second-level arrays to 1. It should set the individual value in that specific child array to 1, because the individual value is what was just returned when I selected myArray[x][y]
. What am I doing wrong / not understanding?