0

So I have a dictionary like this:

var dict = {};

and I have a variable like this:

var string = "Hello";

and I was wondering how I would insert a value into a dictionary, where the key is the variable. Like this.

var dict = {
    "Hello": "Bla Bla Bla"
};

I have tried

dict.`${string}` = "Bla Bla Bla";

but it just gives a syntax error,

Thanks in advance!

1 Answers1

0

You need to use dict[string] not dict.'${string}'

var dict = {};
var string = "Hello";


dict[string] = "Bla Bla Bla";
console.log(dict);
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62