You have some errors in your code:
myArray[i].push( 0 );
to add a new column. Your code (myArray[i][j].push(0);
) would work in a 3-dimensional array as it tries to add another element to an array at position [i][j]
.One correct, although kind of verbose version, would be the following:
var r = 3; //start from rows 3
var rows = 8;
var cols = 7;
// expand to have the correct amount or rows
for( var i=r; i<rows; i++ ) {
myArray.push( [] );
}
// expand all rows to have the correct amount of cols
for (var i = 0; i < rows; i++)
{
for (var j = myArray[i].length; j < cols; j++)
{
myArray[i].push(0);
}
}