-1

Following is my code:

const keyToDisplayMessage = 'REGULAR_HOME';

const cf = format(
    {
      accountName: this.accountName,
    },
    this.pageData.sucessMessages.keyToDisplayMessage,
    this.$route.name
);
    
return cf;

In this keyToDisplayMessage does not get replaced by REGULAR_HOME. However, if I directly use it like

this.pageData.sucessMessages.REGULAR_HOME

then it works.

How can I access keyToDisplayMessage inside the format function?

Pointy
  • 389,373
  • 58
  • 564
  • 602
Trupti
  • 609
  • 1
  • 9
  • 21

1 Answers1

1

For dynamically accessing the property use bracket notation .Update this .

this.pageData.sucessMessages.keyToDisplayMessage

to

this.pageData.sucessMessages[keyToDisplayMessage]
Harmandeep Singh Kalsi
  • 3,215
  • 2
  • 13
  • 22