Results 1 to 3 of 3

Thread: making a variable name variable

Hybrid View

  1. #1
    Join Date
    Aug 2012

    making a variable name variable

    How can i use xyz to name a variable?

    I am trying something like this:

    var xyz = "test";

    var (xyz) = "abc";

    alert (test);

    Would have to display an alert "abc"

  2. #2
    Join Date
    Oct 2007
    You usually aren't supposed to use eval(), but here is one way:

    var xyz = "test";
    eval("var " + xyz + " = 'abc';");
    alert (test);

  3. #3
    Join Date
    Nov 2010
    there's almost always a better option than eval()

    is this what you are talking about?
    var xyz = "test"; 
    window[xyz] = "abc";
    alert (test);
    (creates "test" as a global, ie, window variable)

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center

Recent Articles