I am checking for the existence of an object property with a variable holding the property name in question.
var myObj;
myObj.prop = "exists";
var myProp = "p"+"r"+"o"+"p";
if(myObj.myProp){
alert("yes, i have that property");
};
This is undefined because it’s looking for myObj.myProp but I want it to check for myObj.prop
Or
Or
Note that
hasOwnPropertydoesn’t check for inherited properties, whereasindoes. For example'constructor' in myObjis true, butmyObj.hasOwnProperty('constructor')is not.