Reputation: 1658
I am defining the following variable:
var locationObj = {
latitude: result.geometry.location.lat,
longitude: result.geometry.location.lng,
streetNumber: _.find(addComp, function (comp){return comp.types.indexOf('street_number') > -1}).long_name || '',
route: _.find(addComp, function (comp){return comp.types.indexOf('route') > -1}).long_name || '',
htmlAddress: result.adr_address,
address: result.formatted_address,
vicinity: result.vicinity,
modifiedAt: Date.now()
}
the problem is, the comp
object may be null and i want to write a one liner if within the var object to set the property value as empty if comp
is null. how should i do this?
Upvotes: 2
Views: 693
Reputation: 3084
you could do this:
return comp ? comp.types.indexOf('route') > -1 : false;
this will return false
if comp is null
or undefined
Upvotes: 3