I am displaying some results from Parse on a website but currently the loop is breaking because not all the columns have values in them.
var warningCreator = object.get("creator").get("country");
There are some instances where the user has not selected their country and that results in this error.
I am wondering if there is any way to check whether the result is undefined before calling it.
For iOs I found:
if ([object objectForKey:@"keyPath"]) {
// the object has a value for key keyPath
}
Is there anything simialar for the javaScript SDK?
*Edit (Added more code for clarity):
var WarningPoints = Parse.Object.extend("Warning_Point");
var query = new Parse.Query("Warning_Point");
query.include("creator");
query.include("position");
query.find({
success: function(results) {
markerCount = 0;
if (results.length == 0) {
alert('There are Warning Points found for specified parameters.')
};
for (var i = 0; i < results.length; i++) {
var object = results[i];
var warningCreator = object.get("creator").get("country");
var warningLat = object.get("position").get("lat");
var warningLong = object.get("position").get("long");
if((object.get("position").get("address"))!=null){
warningAddress = object.get("position").get("address");
}
console.log(warningAddress);
var warningName = object.get("name");
}
},
error: function(error) {
alert("Error: " + error.code + " " + error.message);
}
});
The exact error in console is:
Uncaught TypeError: Cannot read property 'get' of undefined - and the line of the error is: warningCreator = object.get("creator").get("country");