Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Sep 2012
    Posts
    79
    Thanks
    2
    Thanked 1 Time in 1 Post

    make a variable a variable

    Code:
    if(LYST1[n]==null){n=0}
    LIST1 in this context is a name of an array

    Code:
    LYST1=new Array("","one","two")

    is it possible to somehow make LYST1 a variable, and depending on the choice of the user link to one array or another?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,642
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Not sure I understand your question. In the code you have there LYST1 is already a variable.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder
    Join Date
    Sep 2012
    Posts
    79
    Thanks
    2
    Thanked 1 Time in 1 Post
    yes, I would like to find a trick to make the choice of variable subject to changes.

    I know it may sound crazy.

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,588
    Thanks
    80
    Thanked 4,497 Times in 4,461 Posts
    Trivial:

    Code:
    var list1 = ["every", "good", "boy", "does", "fine"];
    var list2 = ["good","boys","do","fine","always"];
    
    var useThisList;
    
    // use your own code to choose which list...
    // I will just make a random choice:
    if ( Math.random() < 0.5 ) { useThisList = list1; } else { useThisList = list2; }
    
    // demonstrate that we did choose one of either list1 or list2
    alert( useThisList.join("::") );
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #5
    New Coder
    Join Date
    Sep 2012
    Posts
    79
    Thanks
    2
    Thanked 1 Time in 1 Post
    Thank you very much.


  •  

    Posting Permissions

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