+ 2
JavaScript: Testing Objects for Properties
checkObj("gift") should return "pony". checkObj("pet") should return "kitten". checkObj("house") should return "Not Found". I tried several methods as you can see no way! HELP var myObj = { gift: "pony", pet: "kitten", bed: "sleigh" }; function checkObj(checkProp) { myObj.hasOwnProperty(myObj[]); myObj.hasOwnProperty("kitten"); myObj.hasOwnProperty(checkObj); return checkObj; }
2 Respostas
+ 5
This does what you want:
https://code.sololearn.com/WPyEpt4FsWc5
0
function checkObj(obj, checkprob) {
if (obj.hasOwnProperty(checkprob)) {
return obj[checkprob];
} else {
return "Not Found"
}
}
console.log(checkObj({
gift: "pony",
pet: "kitten",
bed: "sleigh"
}, "Amir"))