Search code examples
javascriptvariables

How to set variable name to other variable value in Javascript?


I have a variable: var a = "testing_here", and I want to create another variable, but I want its name to be the value of a. For example, in a perfect world, it would look something like this: var testing_here = _______

How can I get this desired result?


Solution

  • You can use bracket notation:

    var a = "testing_here"
    window[a] = "___";
    console.log(testing_here);