0

Here is an example of what I'm trying to accomplish:

const a = 'name';
const ${a} = 1;

The second variable should be:

const name = 1;

Is this possible? Thank you in advance.

georg
  • 204,715
  • 48
  • 286
  • 369

2 Answers2

2

Could use an object though, something like

var obj;
var x = "name";
obj[x] = 1;

console.log(obj[x]);
Noble Eugene
  • 371
  • 3
  • 12
0
const a = 'name';
eval (a + " = 37");

This will create a variable name with the value 37.

However, I prefer Nobel Eugene's solution as a better approach to the problem.

Steve Hollasch
  • 1,883
  • 1
  • 17
  • 17