0

I am trying to define a new Object type named attributes from an external config file, however I am not sure how to read the property dynamically as even without apostrophes it is being read as a string.

var dynAtt1 =  vl.popupAttributes.att1 ;
  


    var attributes = new Object({
        dynAtt1 : { title: dynAtt1 }

    })

dynAtt1 is being read literally instead of what it is defined as in the config.

Unmitigated
  • 76,500
  • 11
  • 62
  • 80
  • *"dynAtt1 is being read literally"* - Your second line of code has two instances of that symbol, which one are you talking about? Can you provide a more complete runnable example with observable output and indicate how that output differs from what you expect? – David Dec 02 '20 at 22:26
  • How about `attributes[dynAtt1] = { title: dynAtt1 };` – Mike Christensen Dec 02 '20 at 22:28

1 Answers1

1

You can use a computed property name.

var attributes = {
  [dynAtt1] : { title: dynAtt1 }
}
Unmitigated
  • 76,500
  • 11
  • 62
  • 80