test objects for properties code example
Example 1: Testing Objects for Properties
function checkObj(obj, checkProp) {
if(obj.hasOwnProperty(checkProp)){
return obj[checkProp];
}else{
return "Not Found"
}
}
Example 2: testing objects for properties javascript
var myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false