-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
  • 405,095
  • 59
  • 585
  • 614
Trupti
  • 843
  • 2
  • 11
  • 28

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,315
  • 2
  • 14
  • 26