...

View Full Version : make a variable a variable



eydg
11-01-2012, 10:03 PM
if(LYST1[n]==null){n=0}

LIST1 in this context is a name of an array


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?

felgall
11-01-2012, 10:06 PM
Not sure I understand your question. In the code you have there LYST1 is already a variable.

eydg
11-01-2012, 10:12 PM
yes, I would like to find a trick to make the choice of variable subject to changes.

I know it may sound crazy.

Old Pedant
11-02-2012, 01:35 AM
Trivial:




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("::") );

eydg
11-02-2012, 02:50 AM
Thank you very much.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum