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,627
  • 2
  • 18
  • 28
morne
  • 3,759
  • 8
  • 43
  • 89

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
  • 3,903
  • 3
  • 23
  • 35