1

Why is the objects property undefined, when logging the whole object, that is not the case.

this the log:

console.log(JSON.stringify(obj));
[{"id":"base_data","title":"Base Data","widgetId":"base_data"}] 


console.log(obj.title);
undefined

why???

3
  • var rt = JSON.stringify(obj); then rt.title this will work Commented Aug 22, 2014 at 9:51
  • @cracker — No. That will try to get the title property of a string. Commented Aug 22, 2014 at 9:51
  • @Quentin yeah i got this now thanks :) Commented Aug 22, 2014 at 9:52

2 Answers 2

6

Your object ({}) is inside an array ([]), and you are trying to access the title property of the array, not the object.

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

Comments

0

is it an Array? try

console.log(obj[0].title);

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.