Variable Variables: JavaScript

After spending an hour looking I have a viable solution. I read somewhere it might have trouble with frames. Some insist that you can use arrays to emulate a similar solution and although I see the solution I think this method is more efficient.

    $name = "bob";
    ${$name} = 10;
    echo $bob;  
    var name = "bob";
    window[name] = 10;

Since writing this, however, i found that the array method is far more powerful. You have more control over what happens with the variables. So, although the above is an answer to that question try using arrays first.

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.