After doing some web scraping I am loading the json object using:
const myJson = await JSON.parse(jsonInString);
I am then trying to define a number of properties for db storage with code such as:
lat2 = location.address.coordinate.lat ;
lon2 = location.address.coordinate.lon ;
I'm getting the error in the title. After some investigation I can see that in the cases where this fails, the address object is not defined. Is there a way to avoid the error in node/js without something like:
if (location && location.address && location.address.coordinate ...) {
lat2 = location.address.coordinate.lat ;
}