Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-01-2012, 10:03 PM   PM User | #1
eydg
New Coder

 
Join Date: Sep 2012
Posts: 73
Thanks: 2
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
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?
eydg is offline   Reply With Quote
Old 11-01-2012, 10:06 PM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,532
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
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/
felgall is offline   Reply With Quote
Old 11-01-2012, 10:12 PM   PM User | #3
eydg
New Coder

 
Join Date: Sep 2012
Posts: 73
Thanks: 2
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
yes, I would like to find a trick to make the choice of variable subject to changes.

I know it may sound crazy.
eydg is offline   Reply With Quote
Old 11-02-2012, 01:35 AM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,579
Thanks: 62
Thanked 4,063 Times in 4,032 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 11-02-2012, 02:50 AM   PM User | #5
eydg
New Coder

 
Join Date: Sep 2012
Posts: 73
Thanks: 2
Thanked 1 Time in 1 Post
eydg is an unknown quantity at this point
Thank you very much.
eydg is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:25 AM.


Advertisement
Log in to turn off these ads.