Home > Software design >  How to assign value to a value string in javascript
How to assign value to a value string in javascript

Time:08-21

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);

  • Related