0

I get the values of the first or NAMED key in the object. This one is called Efficacy.

var PSEQ_Obj = $.parseJSON( PSEQ );
var PSEQ_dps1 = PSEQ_Obj.Efficacy;

But I want to know if there is a dynamic way to do this. For instance. Bellow will return Efficacy.

for (label in PSEQ_Obj) break;

But I cant use it lik follows

var PSEQ_dps1 = PSEQ_Obj.label;

So this label is a dynamic, but you cant call it exactly like above. Is there a different way?

Meer
  • 2,765
  • 2
  • 19
  • 28
morne
  • 4,035
  • 9
  • 50
  • 96

1 Answers1

1

you have to use bracket notation instead of dot notation when accessing properties that are stored in variables as follows :

var PSEQ_dps1 = PSEQ_Obj[label];

you can read more about this topic on MDN.

Abdelaziz Mokhnache
  • 4,269
  • 3
  • 25
  • 35