I can't believe this question would not have been asked before, but I searched as much as I could and couldn't find it so here it goes.
I want to test if a dynamically built JavaScript object exists. However when I test this:
var myObject = {};
var dynamicName = "customName";
if(myObject[dynamicName].object == undefined){
myObject[dynamicName].object = "something"; // Make an entry in the dynamic object
alert("The object didn't exist, so we populated it");
}else{
alert("The object already exist");
}
If the object doesn't exist and I try to run the above code I get an error saying "myObject[dynamicName] is undefined" and all javascript execution halts.
Is there a way to check if this object exists I want without causing such an error?