Reputation: 1621
I have an object Structured like below.
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
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