I have a function that receives an array of Strings. These are the names of variables I’m supposed to concat together.
Something like:
function createArray(varNames){
varNames.each( function(varName){
someArray = someArray.concat(varName.items);
});
}
createArray(["array1", "array2"]);
I don’t know how to take a string and select the variable named after it. Any way of doing this in Javascript?
Depends of the scope where the variable was defined. If it was defined in the global scope (inside a browser) you could access it via the
windowobject.For example: