Trying to access the field names of an object nested within another object is causing an issue. In this scenario, attempting to loop through the user object was unsuccessful as an error stating
Object is possibly 'null' or 'undefined'
was encountered.
18 console.log(message[0].message.id);
{
message: {
id: '0301939f-59b5-45f0-bc24-89a4d6840579',
text: 'Everyone is here with the intention to improve.',
html: '<p>Everyone is here with the intention to improve.</p>\n',
type: 'regular',
user: [Object],
attachments: [Array],
latest_reactions: [],
own_reactions: [],
reaction_counts: null,
reaction_scores: {},
reply_count: 0,
cid: 'messaging:3',
created_at: '2021-07-08T20:23:02.354861Z',
updated_at: '2021-07-08T20:23:02.354861Z',
shadowed: false,
mentioned_users: [],
silent: false,
pinned: false,
pinned_at: null,
pinned_by: null,
pin_expires: null,
channel: [Object],
title: 'Welcome to your pod <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6105590b101b191b191159211113081700150413040d00184f0011110d0408054f020e0c">[email protected]</a>'
}
}]
3
User Object:
{
id: 'masterHealthBot',
role: 'admin',
created_at: '2021-06-21T15:12:20.226915Z',
updated_at: '2021-07-08T21:11:34.32916Z',
banned: false,
online: false,
name: 'MasterHealth Bot'
}
3
const message = response.results.map(({ message }) => message.user);
console.log(message[0].id); // not working
console.log(message.map(({user}) => user.id)) gives a user undefined error
Any assistance on resolving this issue would be greatly valued. Thank you for your time.