Testing Objects for Properties
function checkObj(obj, checkProp) {
if(obj.hasOwnProperty(checkProp)){
return obj[checkProp];
}else{
return "Not Found"
}
}
4.3
10
var myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false
Thank you!
10
0
Are there any code examples left?
New code examples in category TypeScript