How to get attribute title from this array which has only one data record, I just want to print title, for example If I write console.log(data) it shows the result as shown in picture below, but when I write conosle.log(data[0].attributes.title) it shows 0 is undefined, how can I print title in console.log?
CodePudding user response:
Looks like you want:
console.log(data.posts.data[0].attributes.title)
updated based on your comment that the log in the image is of 'data'.
update 2: because data is populated using a hook that is probably asynchronous, you should expect it may be undefined or null until some promise is resolved.
if (data) {
console.log(data.posts.data[0].attributes.title)
} else {
console.log('Zzz... waiting for data')
}
CodePudding user response:
posts.data[0].attributes.title = "Trump got some money..." data[0].attributes.title = undefined

