I've got 2 functions. One to create 2D array, the other to print it. Something is wrong with the creating function, because when I create and send an 2D array by myself, everything is fine. But when I try to do this through the create funcion, the console is empty (but no errors). Could you help me?
function print2DArray (array2D) {
for (var i = 0; i < array2D.length; i++) {
for (var j = 0; j < array2D[i].length; j++) {
console.log(array2D[i][j]);
}
}
}
function create2DArray (rows, columns) {
var array2D = [];
for (var i = 0, x = 0; i < rows; i++, x++) {
array2D[i] = x;
for (var j = 0; j < columns; j++) {
x++;
array2D.push(x);
}
}
return array2D;
}
/* ← Here everything is fine
var arr = [
[11, 12],
[42, 2],
[-4, -120],
[0, 0],
[1, 34],
];
print2DArray(arr);
*/
print2DArray(create2DArray(2, 3)); ← Empty console