mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-04-13 04:00:12 -04:00
chore(i18n,learn): processed translations (#50292)
This commit is contained in:
@@ -8,25 +8,24 @@ dashedName: testing-objects-for-properties
|
||||
|
||||
# --description--
|
||||
|
||||
指定されたオブジェクトにプロパティが存在するかどうかをチェックできると便利なことがあります。 オブジェクトの `.hasOwnProperty(propname)` メソッドを使用すると、そのオブジェクトが指定されたプロパティ名を持っているかどうかを確認することができます。 `.hasOwnProperty()` はプロパティの有無に応じて、`true` または `false` を返します。
|
||||
To check if a property on a given object exists or not, you can use the `.hasOwnProperty()` method. `someObject.hasOwnProperty(someProperty)` returns `true` or `false` depending on if the property is found on the object or not.
|
||||
|
||||
**例**
|
||||
|
||||
```js
|
||||
const myObj = {
|
||||
top: "hat",
|
||||
bottom: "pants"
|
||||
};
|
||||
function checkForProperty(object, property) {
|
||||
return object.hasOwnProperty(property);
|
||||
}
|
||||
|
||||
myObj.hasOwnProperty("top");
|
||||
myObj.hasOwnProperty("middle");
|
||||
checkForProperty({ top: 'hat', bottom: 'pants' }, 'top'); // true
|
||||
checkForProperty({ top: 'hat', bottom: 'pants' }, 'middle'); // false
|
||||
```
|
||||
|
||||
最初の `hasOwnProperty` は `true` を返し、2 つ目は `false` を返します。
|
||||
The first `checkForProperty` function call returns `true`, while the second returns `false`.
|
||||
|
||||
# --instructions--
|
||||
|
||||
関数に渡されたオブジェクト (`obj`) に特定のプロパティ (`checkProp`) が含まれているかどうかをテストするように、関数 `checkObj` を変更してください。 プロパティが見つかった場合は、そのプロパティの値を返してください。 見つからなかった場合は、`"Not Found"` を返してください。
|
||||
Modify the function `checkObj` to test if the object passed to the function parameter `obj` contains the specific property passed to the function parameter `checkProp`. If the property passed to `checkProp` is found on `obj`, return that property's value. If not, return `Not Found`.
|
||||
|
||||
# --hints--
|
||||
|
||||
|
||||
Reference in New Issue
Block a user