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
  • 211,518
  • 52
  • 313
  • 390

2 Answers2

2

Could use an object though, something like

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

console.log(obj[x]);
Noble Eugene
  • 523
  • 1
  • 5
  • 15
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
  • 2,011
  • 1
  • 20
  • 18