【发布时间】:2019-04-18 05:37:29
【问题描述】:
我想声明一个 4 维数组,然后用 for() 循环一些东西 - 然后程序中断。这是我的代码:
打字稿:
MoarInfo: any = [[[[]]]];
JavaScript:
constructor(){
for(var i = 0; i < this.AllDataInfo[this.KontoAktuellYearIndex][this.KontoAktuellMonth].length; i++){
for(var a = 0; a < this.AllDataInfo[this.KontoAktuellYearIndex][this.KontoAktuellMonth][i].length; a++){
for(var b = 0; b < this.AllDataInfo[this.KontoAktuellYearIndex][this.KontoAktuellMonth][i][a].length; b++){
this.MoarInfo[i][a][b][0] = this.AllDataInfo[this.KontoAktuellYearIndex][this.KontoAktuellMonth][i][a][b][0];
this.MoarInfo[i][a][b][1] = this.AllDataInfo[this.KontoAktuellYearIndex][this.KontoAktuellMonth][i][a][b][1];
this.MoarInfo[i][a][b][2] = 'DetailsSpan';
}
}
}
}
问题肯定出在MoarInfo[][][][] 数组上。我在没有它的情况下测试了我的代码,它工作正常。我也为 Typescript 数组声明尝试了以下可能性:
Moarinfo: any[]; MoarInfo = []; MoarInfo = [[[[]]]]; MoarInfo: any[][][][] = [[[[]]]];
在 JavaScript 中,我尝试声明一个新数组,然后将一些元素推送到 MoarInfo 数组上,具有不同的功能(拆分、取消移位、推送、连接),但没有任何效果。
我做错了什么?
【问题讨论】:
标签: javascript html arrays angular typescript