1

Currently, I am trying to localize my Chrome extension with various other languages and I am getting the variable message from _locales using i189.getmessage and then I want to use it inside a const Object dictionary. Below is the code:

var stad = chrome.i18n.getMessage("stand");
const emoji_map = {
  "__1_person__": "",
  "2 people": "",
  "3 people": "",
  "4 people": "",
  "stad": "sdss",
}

I want to use the value of the stad variable in place of "stad", but don't know how to do this.

Makyen
  • 31,849
  • 12
  • 86
  • 121
rahul kapoor
  • 51
  • 3
  • 10
  • MDN documentation: [Object initializer: Computed property names](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer#Computed_property_names) – Makyen Jan 02 '17 at 16:03

1 Answers1

0

Just use the []:

var stad = chrome.i18n.getMessage("stand");
const emoji_map = {
  "__1_person__": "",
  "2 people": "",
  "3 people": "",
  "4 people": "",
  [stad]: "stand",
}

Works fine for me:

preview

Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252