Javascript: Server sided dynamic variable names

hexacyanide picture hexacyanide · Sep 26, 2012 · Viewed 15.7k times · Source

How would I create dynamic variable names in NodeJS? Some examples say to store in the window variable, but I was assuming that is client-side Javascript. Correct me if I'm wrong.

Answer

Bill picture Bill · Sep 26, 2012

Generally you would do something like:

var myVariables = {};
var variableName = 'foo';

myVariables[variableName] = 42;
myVariables.foo // = 42