我收到一个类型错误,指出在向html页面添加输入时,数组testA [i]是未定义的。我已经在阵列设置和我试图使用推送方法添加到阵列即([0] [货币])js中的未定义参数
function Test() {
var testA = [];
for (i = 0; i < 4; i++) {
this.currency = prompt("Please enter a 3-letter currency abbreviation", "");
testA[i].push(currency);
}
}
var index = new Test();
的第二部分货币的值添加到阵列
任何帮助,为什么数组是未定义的,将不胜感激。
注意:我现在已经尝试testA.push(currency)和testA [i] = this.currency,并且仍然像以前一样得到相同的错误。
注意:最终版本应该让它遍历4个不同的问题,并且每次将这些问题添加到数组中。在循环结束时,应该创建一个新的数组变体,并将输入的新数据集添加到它。像 for(i = 0; i < 4; i++) { testA[i] = i; for(j = 0; j < 4; j++) { this.currency = prompt("Please enter a 3-letter currency abbreviation", ""); testA[i][j] = this.currency; } }
但在这个时候我只是想让它工作。
忘记提到,这需要循环4个不同的部分。因此我需要货币价值在指数。 testA [i] [0] < - 这里。然后一旦循环结束,我就会上升1,并再次提出问题。testA [3] [currency] testA [2] [currency] testA [3] [currency] – soul6942