I'm trying to do a simple condition check of a property with the following:
if ( message.updates[0].message != 'undefined' && message.updates[0].message.message != 'undefined') {
^
TypeError: Cannot read property 'message' of undefined
I also tried:
if (typeof message.updates[0].message.message != 'undefined')
if (message.updates[0].message.message.length > 0)
if (typeof message.updates[0].message.message != undefined)
if ( message.updates[0].message != 'undefined' && message.updates[0].message.message != 'undefined') {
None work, I'm getting the same error everytime.
here is the data I'm doing the check on as requested in the answers.
for the below data, it should not enter the IF and simply pass it, not give error of undefined.
Thanky you!
{
_: 'updates',
updates: [
{
_: 'updateReadChannelInbox',
flags: 0,
channel_id: 1415629976,
max_id: 46,
still_unread_count: 0,
pts: 48
},
{
_: 'updateNewChannelMessage',
message: [Object],
pts: 48,
pts_count: 1
}
],
users: [
{
_: 'user',
flags: 33561715,
self: true,
contact: true,
mutual_contact: true,
deleted: false,
bot: false,
bot_chat_history: false,
bot_nochats: false,
verified: false,
restricted: false,
min: false,
bot_inline_geo: false,
support: false,
scam: false,
apply_min_photo: true,
first_name: 'Andrei',
phone: '40756274034',
photo: [Object],
status: [Object]
}
],
chats: [
{
_: 'channel',
flags: 286977,
creator: true,
left: false,
broadcast: false,
verified: false,
megagroup: true,
restricted: false,
signatures: false,
min: false,
scam: false,
has_link: false,
has_geo: false,
slowmode_enabled: false,
call_active: false,
title: 'tester',
photo: [Object],
date: 1616253844,
version: 0,
admin_rights: [Object],
default_banned_rights: [Object]
}
],
date: 1616336995,
seq: 0
}