mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-30 21:03:58 -05:00
1004 B
1004 B
id, title, challengeType, videoUrl, forumTopicId
| id | title | challengeType | videoUrl | forumTopicId |
|---|---|---|---|---|
| 567af2437cbaa8c51670a16c | 测试对象的属性 | 1 | https://scrimba.com/c/cm8Q7Ua | 18324 |
--description--
有时检查一个对象属性是否存在是非常有用的,我们可以用.hasOwnProperty(propname)方法来检查对象是否有该属性。如果有返回true,反之返回false。
示例
var myObj = {
top: "hat",
bottom: "pants"
};
myObj.hasOwnProperty("top"); // true
myObj.hasOwnProperty("middle"); // false
--instructions--
修改函数checkObj检查myObj是否有checkProp属性,如果属性存在,返回属性对应的值,如果不存在,返回"Not Found"。
--hints--
checkObj("gift")应该返回"pony"。
assert(checkObj('gift') === 'pony');
checkObj("pet")应该返回"kitten"。
assert(checkObj('pet') === 'kitten');
checkObj("house")应该返回"Not Found"。
assert(checkObj('house') === 'Not Found');