I want to assign value to a value string. Sample as below written in javascript
var q="e"; [q]='hio';
e should have value of 'hio'
JavaScript: Assign a value to a string
the above link solves the problem. But using eval is not right approach. So I am looking for better approach.
CodePudding user response:
You could use an object:
var myObj = {};
var q = "e";
myObj[q] = "hio";
console.log(myObj.e);