View Full Version : make a variable a variable

11-01-2012, 11:03 PM

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?

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

11-01-2012, 11: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, 02:35 AM

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

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