0

In my Ajax request the response data is an object like this:

enter image description here

how is possible to access value.

note: idVariable is a variable.

data.test1.idVariable.test2.value

Above code result is: undefined.

3
  • 3
    data.test1[idVariable].test2.value Commented Feb 21, 2016 at 8:24
  • Yep, Correct. Thank you haim770. Commented Feb 21, 2016 at 8:29
  • Duplicate of stackoverflow.com/questions/4244896/… Commented Feb 21, 2016 at 8:42

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Already answered and acknowledged as so in comment. Also posted a duplicate link.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.