JavaScript似乎没法直接声明二维数组
只能先声明一维再声明第二维
如下:
var a = new Array(4);
for (let i = 0; i < a.length; i++) {
a[i] = new Array(4);
}
for (let i = 0; i < 4; i++) {
for (let j = 0; j < 4; j++) {
a[i][j] = i * j;
}
}
console.log(a);
JavaScript似乎没法直接声明二维数组
只能先声明一维再声明第二维
如下:
var a = new Array(4);
for (let i = 0; i < a.length; i++) {
a[i] = new Array(4);
}
for (let i = 0; i < 4; i++) {
for (let j = 0; j < 4; j++) {
a[i][j] = i * j;
}
}
console.log(a);