0
console.log(window.Ab); //returns 12345

I would like to rename Ab to something that has meaning to be used throughout the code of my chrome extension I was thinking about doing something like this

const meaningfulObjectName = 'Ab'
console.log(window.meaningfulObjectName); // should return the value of window.Ab, 12345

However I seem to be making a mistake. How can I correct this?

3jay1
  • 65
  • 6

1 Answers1

0

You can use bracket notation to access the property.

Here's how you can do this:

const meaningfulObjectName = 'Ab';
console.log(window[meaningfulObjectName]); // This will return the value of window.Ab, 12345
jagmitg
  • 4,236
  • 7
  • 25
  • 59