Vallabha
Vallabha

Reputation: 1621

How to get the object property dynamically in the run time using the name of the property

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.

Upvotes: 1

Views: 128

Answers (1)

Pranav C Balan
Pranav C Balan

Reputation: 115282

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

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

For more about bracket notation : visit here

Upvotes: 1

Related Questions