1

I have an object Structured like below.

enter image description here

Now what my intention is to get the Capitals/State value on the run time dynamically using the property name, for example.

var PropertyName='Capitals';
JSON.parse(ValueList)[0].PropertyName;

How to achieve this. Thanks.

Vallabha
  • 1,591
  • 3
  • 13
  • 21

1 Answers1

1

You can use bracket notation([]) for object selector

var PropertyName='Capitals';
JSON.parse(ValueList)[0][PropertyName];

For more about bracket notation : visit here

Pranav C Balan
  • 113,687
  • 23
  • 165
  • 188
  • Specifically, the values for Javascript object properties can be accessed using the dot notation (Object.property) or bracket notation (Object["property"]). See more here: https://stackoverflow.com/questions/4968406/javascript-property-access-dot-notation-vs-brackets – heartyporridge Jul 08 '15 at 03:12