danca
10/21/2014 7:08:00 AM
Il 20/10/2014 23:11, Mel Smith ha scritto:
> Problem:
>
> I have seveal undefined objects/vrbls (?) in an array. I wish each of
> these objects to
> acquire a new value in a loop thru the array and
> my brain has gone dead again :(
>
> // Assume :
>
> var a,b,c,d ;
>
> var abcd = [a,b,c,d] ;
>
> var somestr = "" ;
>
> for (var i= 0; i<abcd.length; i++) {
> somestr = i.toString() ;
> // I wish to place the current value of somestr in each
> // of the named but undefined objects/vrbls that are carried in the abcd
> array
>
> // e.g.,
> abcd[i] = somestr ; // but this, of course, ruins everything :(
>
> // what is the correct statement please ?
> }
>
> Result I wish here is:
>
> // a has value '0'
> // b has value '1'
> // c has value '2'
> // d has value '3'
>
>
> Thanks for (another) kick-in-the-butt.
>
> -Mel Smith
>
>
>
Maybe something like this?
var a,b,c,d ;
var abcd = ["a","b","c","d"] ;
for (var i= 0; i<abcd.length; i++) {
eval(abcd[i]+"="+i);
}
Dan