Q:

How to access constant variable inside return statement?

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?

A:

For dynamically accessing the property use bracket notation .Update this .
this.pageData.sucessMessages.keyToDisplayMessage

to
this.pageData.sucessMessages[keyToDisplayMessage]

