i want to access the field names of an object nested within another object. In this example i want to map through user object. i tried to map through message ojbect and store it in a variable. then tried to map again but its giving an error saying Object is possibly 'null' or 'undefined'.
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 d8jqzxzxp8@privaterelay.appleid.com!' } } ]
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)) give user undefined error
any help is greatly appreciated. thanks for your time.