Search code examples
javascriptnode.jsdynamic-variables

Javascript: Server sided dynamic variable names


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.


Solution

  • Generally you would do something like:

    var myVariables = {};
    var variableName = 'foo';
    
    myVariables[variableName] = 42;
    myVariables.foo // = 42