0

I'm having problem getting a value from array contains json. Here is the JSON i'm getting (printed by console.log(rows[0]) ) :

[ { User_ID: 28,
    Email: '[email protected]'} ]

But when trying to print the User_ID or Email:

console.log(rows[0].User_ID)

The output is undefined.

What am I doing wrong ?

1
  • Have you parsed the JSON data already? Commented Sep 30, 2013 at 13:51

2 Answers 2

2

If that's what you get after executing console.log(rows[0]), then you have another array to deal with. This should do the trick:

console.log(rows[0][0].User_ID); //28

Reason being, rows[0] returns an array, so once again you need to select the appropriate index from that returned value: rows[0][0]. This will give you the object you want.

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

Comments

1

rows[0] looks like an array. Try,

console.log(rows[0][0].User_ID)

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.