In the below code his._notifications
is an array of objects, each object contains the properties shown below.
What I am trying to do is to check if each object not passed to the function func()
was pushed into the array or not?
So I am using .find()
and I expect it returns true
if the object was passed to the function or if it already exists in the array, and false
otherwise.
But the below log statement prints undefined
! Why isExists
is undefined? And what is the recommended way to check if an item is duplicate or not in an array?
code:
func(noti)
const isExists = this._notifications.find((obj) =>
obj.title === noti.safeTitle
&& obj.text === noti.safeText
&& obj.bannerTitle === noti.safeBannerTitle
&& obj.bannerText === noti.safeBannerText
&& obj.icon === noti.icon
&& obj.onClickCallback === noti.onClickCallback
&& obj.eNotificationType === noti.notificationType
&& obj.deleteable === noti.deletable
&& obj.withBanner === noti.withBanner
);
logger.info('[isNotificationExists] For the current notification: ', JSON.stringify(notification), ' isExists: ', isExists);