I'm looking to access a variable by using a variable name dynamically computed at runtime. Example code:
var firstSecond = ['a', 'b', 'c'];
var tempDatabase = 'first';
var tempTable = 'Second';
var copyArray = MAGIC(tempDatabase + tempTable);
copyArray should be the array: ['a', 'b', 'c']. Is there a way to achieve this?
copyArrayis equal to"firstSecond"not an array.MAGIC = eval, but you really should not. Store all the possible arrays in an object, and reference them by a dynamic property name.