[Solved] How to dynamically create JavaScript variable based on string value? [closed]


You could use an object like this.

var obj = {};
var name="jayesh";
obj[name] = 'some value';
var myvalue = obj.jayesh;

You can create a global variable like this:

var name="jayesh";
window[name] = 'some value';

You can also use eval but this can cause security issues so use with caution!

var name="jayesh";
var evalString = 'var ' + name + ' = "some value"';
eval(evalString);

3

solved How to dynamically create JavaScript variable based on string value? [closed]