For loop variables/arrays

in a for loop, I want to assign new arrays and possibly their initial value as well… I can do the values without problem, the array name has turned out to be tricky for me.

Example:

for(i=1;i<10;i++){

myarray*=[this.myvariable*];
}

with the intent of getting

myarray1=myvariable1;
myarray2=myvariable2;
myarray3=myvariable3;

I know Im missing something, just cant think straight.

have you done a:

myArray=new Array(10);

???

// Intialize the Array
myarray = new Array();
for (var i=0; i<10; i++) {
        myarray* = this.myvariable*;
}

*Originally posted by Dravos *
**have you done a:

myArray=new Array(10);

??? **

huh? didnt c ur post!!!

OK h88 seems u pick up on everything !! so if i want to do it in your php stylee i just click php then type and then click php to end?

//my code stylee stuff;
myArray=newArray(10)

better?

nope still dont work dammit…have to disable them smilis then, is there another way to get rid of the smiley when you do 0) ??

I’ll give it a shot too :stuck_out_tongue:

for(i=1;i < 10;i++){
  myarray*=this["myvariable"i];
}

pom :cowboy:

Long time, Ivan… preparing something?

Hum, actually, this surprises me a bit:

myarray1=myvariable1;
myarray2=myvariable2;
myarray3=myvariable3;
I mean, myarray is an array, right?

*Originally posted by ilyaslamasse *
**Hum, actually, this surprises me a bit:I mean, myarray is an array, right? **

offcourse, from its name!!!:stuck_out_tongue:

yours,
h88

i have to agree with ilyaslamasse

looks like it supposed to be

for(i=1;i<10;i++)
{
[“myArray”+i]=[“myVariable”+i];
}

but then again it could be

myArray[1]=myVariable[1]
myArray[2]=myVariable[2]
myArray[3]=myVariable[3]

*Originally posted by Dravos *
**i have to agree with ilyaslamasse

looks like it supposed to be

for(i=1;i<10;i++)
{
[“myArray”+i]=[“myVariable”+i];
}

but then again it could be

myArray[1]=myVariable[1]
myArray[2]=myVariable[2]
myArray[3]=myVariable[3] **

Output ---------------
Variable _level0.i = 10
Variable _level0.my0 = 0
Variable _level0.my1 = 1
Variable _level0.my2 = 2
Variable _level0.my3 = 3
Variable _level0.my4 = 4
Variable _level0.my5 = 5
Variable _level0.my6 = 6
Variable _level0.my7 = 7
Variable _level0.my8 = 8
Variable _level0.my9 = 9

thats wrong, cuz it will just create some normal variables :evil:

yours,
h88

within the [] brackets is alwasy the index of the element of the array

[] have some more use. but you cant use them without an object in front of them:

some alternatives:

varname="myvar";
_root[varname] = new Array(); 
for (var i=0; i<10; i++) { 
_root[varname]* = this.myvariable*; 
}

and

for(var i=0; i<10; i++) {
     eval("myvar"+i) = this.myvariable*;
}

hope this helps!

yours,
h88

assuming you want i number of arrays each containing eval(myVariable+i) (as opposed to myVariable*) as their first element, something like this:


for(i=0;i<10;i++){
   this["myArray"+i] = [this["myVariable"+i]];
}

but as everyone seems to be, i’m a little confused as to just what you’re trying to accomplish.

*Originally posted by sbeener *
*assuming you want i number of arrays each containing eval(myVariable+i) (as opposed to myVariable) as their first element, something like this:


for(i=0;i<10;i++){
   this["myArray"+i] = [this["myVariable"+i]];
}

but as everyone seems to be, i’m a little confused as to just what you’re trying to accomplish. **

ask Iammontoya, i was just helping in coding, correcting the syntax, i have no idea wut he wants to achieve?

i was asking inigo. :wink:

The whole point is: did Inigo really mean myarray1 (variable, not an array, hence my question :)) or did he mean myarray[1] (an array this time).

pom :slight_smile:

hmm, i really dunno :q::q:

Whew… thank you all for your replies.

What I actually want to do is this:

I am loading a bunch of variables from a text file. The text variables are in the form

variable1=value1,value2,value3&variable2=value1,value2,value3

In order to use the values for each variable I have to split them and put them in arrays.


 myarray=variable1.split(",");   

since I am loading several variables, I need to create a number of arrays that is equal to the number variables I have. At the same time, I was populating such arrays with the split value of the variable.

Hence…



for(i=1;i<10;i++){//where 10 is the number of variables loaded

myarray*=[this.myvariable*]; /* This actually is "myarray"+i , but I know that doesn't work. The part to the right of the assignment works fine and it is meant to circumvent to problem of "myvariable"+i    
*/
}


this was all meant to produce something like this…

myarray1=myvariable1.split(","); //each one is a different array
myarray2=myvariable2.split(",");
myarray3=myvariable3.split(",");




I somehow knew Supra would come out of hiding on this one. Thank's to all for your responses!

Pom, I've been so busy I just had to post this one, even though I am like you (and others on this board), I like to figure these out on my own, it's just part of the fun. However, I don't have the time this time around. So, your help (everyone's help) is greatly appreciated.

btw, Supra… your answer makes sense to me. I will try in a few minutes.

Pom, what’s up with you, man. How have you been?

based on all the above threads…

eval(“myarray”+i)=etc… does not work. Left of the assignment must be variable.

this[“myarray”+i]= does not work for the same reason

still looking for any takers. Now, of course, by adding the .split mentioned above, things get creepy! heheheh…

Oh, nothing very interesting. I’ve just finished my semester, had my exams… I’m going to Viet-Nam in a few days :beam:

Concerning your problem, could you post all the code you are using?

Cheers.

pom :asian: