Reputation: 313
In my Ajax request the response data is an object like this:
how is possible to access value
.
note: idVariable
is a variable.
data.test1.idVariable.test2.value
Above code result is: undefined
.
Upvotes: 0
Views: 49
Reputation: 958
When you are using a variable to name a key in a javascript object you are supposed to use bracket notation. E.g:
var idVariable = 8;
var value = data.test1[idVariable].test2.value;
Otherwise, you are accessing a key names idVariable
, instead of 8
Upvotes: 1