1
I got this one that’s gonna take all the data "this.retorno += data.usuarios[i].descr;" and "this.retorno += data.usuarios[i].valor;" wanted to take this values and make an array with them, then get these values stored in the array on another page with javascript.
I thought of something like this:
var myarry = new Array();
for (i = 0; i < this.qtd; i++) {
if (i == (this.qtd - 1)) {
this.retorno += data.usuarios[i].descr;
this.retorno += data.usuarios[i].valor;
} else {
// this.retorno += data.usuarios[i].descr;
// this.retorno += data.usuarios[i].valor;
myarray[0] = this.retorno += data.usuarios[i].descr;
myarray[1] = this.retorno += data.usuarios[i].descr;
myarray[2] = this.retorno += data.usuarios[i].descr;
myarray[3] = this.retorno += data.usuarios[i].descr;
myarray[4] = this.retorno += data.usuarios[i].descr;
alert(myarray[0]);
}
Utilize:
myarray.push(seuvalor);(Also note that your statement is different from the one you use).var myarry = new Array();and you’re calling formyarray.– Rafael Withoeft
Do you want each pair to be a position in the array? It would be nice to post a more complete example that can be executed. See How to create a minimal, complete and verifiable example.
– bfavaretto
@bfavaretto That’s even if each pair is an array position !
– nardo_bruxo
btw, you can use
var myarray = []instead ofnew Array(). It’s simpler and more efficient.– hugomg