javascript - undefined parameter in js -
i receiving type error stating array testa[i] undefined whenever add input html page. have array set , i'm trying add value of currency array using push method add second part of array i.e([0][currency])
function test() { var testa = []; (i = 0; < 4; i++) { this.currency = prompt("please enter 3-letter currency abbreviation", ""); testa[i].push(currency); } } var index = new test();
any why array undefined appreciated.
note: have tried both testa.push(currency) , testa[i] = this.currency, , still same error before.
note: final version should have loop through 4 different questions asked , each time adding these array. @ end of loop new variant of array should made , new set of data entered added it. for(i = 0; < 4; i++) { testa[i] = i; for(j = 0; j < 4; j++) { this.currency = prompt("please enter 3-letter currency abbreviation", ""); testa[i][j] = this.currency; } }
but @ point in time i'm trying work.
you don't use push
method on index. use on array itself.
replace this
testa[i].push(currency);
with this
testa.push(currency);
Comments
Post a Comment