I'm trying to filter an array of objects. When i console.log the Array all the properties are filled with data but, when I use .filter it throws errors saying "Cannot read property 'id' of null.
Here is the code:
this.hubConnection.on('HorsesChanged', async (data: HorseModel[]) =>
{
if(await this.guard.checkPermission([PermissionType.SeeAllHorses]))
{
this.allHorses$.next(data)
}
else{
console.log(data) //owner.id, jockey.id and trainer.id of all horses is filled
this.allHorses$.next(data.filter(x=>x.owner.id==this.loggedInPersonId ||
x.jockey.id==this.loggedInPersonId ||
x.trainer.id==this.loggedInPersonId)) // throws error saying cannot read id of null
}
}
);