Is there a simple way to check if Null and not put anything?

Hi,
Right now I am using

this.locationPlaceholder = this.event.location.hiddenLocationToggle ? this.event.location.home + ' ' + this.event.location.street + ', ' + this.event.location.city : 'Event Address';

this works great but sometimes I don’t have an event.location.home or street and then in my placeholder I get null null, Los Angeles.

Is there a simple way to say if its null to not put anything or do I have to do another if statement to check for if those fields are null?

You could use (this.event.location.street || '') but then you’ll still up with extra spaces and sometimes even a random comma as well.

A foolproof but long winded solution might be:

const loc = this.event.location;
this.locationPlaceholder = loc.hiddenLocationToggle 
    && [
        [loc.home, loc.street].filter(a=>a).join(' '),
        loc.city
    ].filter(a=>a).join(', ')
    || 'Event Address';

Notice using && || instead of ? : so that if all of home, street AND city are blank/null then it still defaults to ‘Event Address’.

Why do you speak English so well?:smile:

Try this

this.locationPlaceholder = this.event.location.hiddenLocationToggle ? (this.event.location.home ? this.event.location.home : '') + ' ' + (this.event.location.street ? this.event.location.street : '') + ', ' + this.event.location.city : 'Event Address';