Kglad...[b] _root["p"+p][j-1][/b] !!! [quoted text, click to view] "kglad" <webforumsuser@macromedia.com> wrote in message news:dm32hv$puo$1@forums.macromedia.com... > for (var p = 0; p<10; p++) { > _root["p"+p] = []; > for (var j = 1; j<=5; j++) { > _root["p"+p][j] = _root["TTArray"+j][p]; > } > }
Basically I have data in 5 arrays called TTArray1 - TTArray5. I want to take the first piece of data from each of these arrays and it into a new array. I then want to take the second piece of data from each of these arrays and place that into antoher new array and so on, untill I have extracted all the data from my original TTArray1 - TTArray5. i.e. I am changing the order of the arrays. //please note there are 10 pieces of data in each of the arrays. for (p=0;p<10;p++){ id.p = new Array(); id.p[0]= TTArray1[p]; id.p[1]= TTArray2[p]; id.p[2]= TTArray3[p];} but this does not work... I think it is because I'm getting confused with the'.' I thought that consentened but maybe that is only strngs and in php??? If anyone knows what i am onabout or can help that would be ace.. thanks JOnnie.
which code do you want explained? surveyor created one 2-dimensional array to contain all your array elements and i created 10 1-dimensional arrays to contain all your array elements. beyond that (noting surveyor's correction of my code), there isn't any significant difference.
No problem Okay... here's what I did with my code.. First I made an array, id to hold the final array. id = [ ]; //we loop through p from 0 to 9 for each of the elements in the arrays for(var p=0;p<10;p++){ //now we have an array to hold all the "p"th values of your arrays //For example, for the first time this code loops, we will have //id[0] = [ ], which will be the array we hold all the first elements of //the TTarrays id[p] = [ ]; //We loop t from 1 to 5 for each array for(var t=1;t<=5;t++){ //Because you started at TTArray1 and arrays are 0 based, //the First element in id[p] is id[p][0] which we set to this["TTArray"+t][ p ] id[p][t-1] = this["TTArray"+t][p]; } } Sorry I'm pretty vague, because I have to go somewhere... hopefully Kglad will explain better.
I think this should do the trick: id = [ ]; for(var p=0;p<10;p++){ id[p] = [ ]; for(var t=1;t<=5;t++){ id[p][t-1] = this["TTArray"+t][p]; }
for (var p = 0; p<10; p++) { _root["p"+p] = []; for (var j = 1; j<=5; j++) { _root["p"+p][j] = _root["TTArray"+j][p]; }
Don't see what you're looking for? Try a search.
|