.hasOwnProperty(propname)
method of objects to determine if that object has the given property name. .hasOwnProperty()
returns true
or false
if the property is found or not.
Example
```js
var myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false
```
checkObj
to test if an object passed to the function (obj
) contains a specific property (checkProp
). If the property is found, return that property's value. If not, return "Not Found"
.
checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift")
should return "pony"
.'
testString: 'assert(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "gift") === "pony");'
- text: 'checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet")
should return "kitten"
.'
testString: 'assert(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "pet") === "kitten");'
- text: 'checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house")
should return "Not Found"
.'
testString: 'assert(checkObj({gift: "pony", pet: "kitten", bed: "sleigh"}, "house") === "Not Found");'
- text: 'checkObj({city: "Seattle"}, "city")
should return "Seattle"
.'
testString: 'assert(checkObj({city: "Seattle"}, "city") === "Seattle");'
- text: 'checkObj({city: "Seattle"}, "district")
should return "Not Found"
.'
testString: 'assert(checkObj({city: "Seattle"}, "district") === "Not Found");'
- text: 'checkObj({pet: "kitten", bed: "sleigh"}, "gift")
should return "Not Found"
.'
testString: 'assert(checkObj({pet: "kitten", bed: "sleigh"}, "gift") === "Not Found");'
```