0

Hey all Here is my code:

function SuccessOccur(data, status, req) {
    if (status == "success") {
       var xml = req.responseText.toString();
       console.log(xml);
       var jSON = $(xml).find('empResult').text();
       var obj = jQuery.parseJSON(jSON);
       console.log(obj.firstName);
    }
}

Oddly enough I get this as a value:

undefined

If I just put this:

console.log(obj);

Then I would get all the values:

enter image description here

So, what am I missing?

1
  • 1
    "what am I missing?" 0: Object Commented Dec 1, 2014 at 16:02

1 Answer 1

4

obj is not an object, it's an array, that's why it's in [] brackets with a 0 as the key, and a given length of 1 in the console output you've posted. Arrays are accessed like this

console.log(obj[0].firstName);
Sign up to request clarification or add additional context in comments.

Comments

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.