puppeteer701
puppeteer701

Reputation: 1285

objects property undefined, even if not true

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???

Upvotes: 1

Views: 36

Answers (2)

playing
playing

Reputation: 11

is it an Array? try

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

Upvotes: 0

Quentin
Quentin

Reputation: 943097

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);

Upvotes: 6

Related Questions