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.

1
  • No, you can not.
    – Pran Sukh
    Commented Oct 6, 2021 at 19:43

2 Answers 2

2

Could use an object though, something like

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

console.log(obj[x]);
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.