I have an array of strings:
arr = ["bar","baz"]
and I have a few variables:
var bar = 'Hello';
var baz = 'bye';
using the array, how can I ouput:
hello
bye
I know how to loop, but, how can i use a string to refence a variable?
The best option is to store the variables as properties within an object, and reference them that way:
var data = {
    bar: "Hello",
    baz: "Bye"
};
arr.forEach((key) => doStuff(data[key]));
Failing that, if you have access to some other scope (perhaps this during a method call), you can keep the variable as properties on the scope.
If you don't have any other scope available and no good options, all global variables are attached to the self (or window, when available) scope, so you can use the same sort of window[key] access.
var arr = new Array(); arr["somevalue"] = "Hello"; var bar = arr["somevalue"];[ ]operator), and global variables are object properties (of the global object,windowin a browser).newup anArrayspecifically, then use it as an associative container? Just use an object (orMap, where available).