このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docsコミュニティーについてもっと知り、仲間になるにはこちらから。
Reflect.has()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2016年9月.
静的なReflect.has() メソッドは、機能としてはin 演算子のように動作します。
In this article
試してみましょう
const object1 = { property1: 42,};console.log(Reflect.has(object1, "property1"));// Expected output: trueconsole.log(Reflect.has(object1, "property2"));// Expected output: falseconsole.log(Reflect.has(object1, "toString"));// Expected output: true構文
Reflect.has(target, propertyKey)
引数
targetプロパティを探す対象のオブジェクト。
propertyKeyチェックするプロパティ名。
返値
対象がプロパティを持つかどうかを示すBoolean 値。
例外
解説
Reflect.has メソッドは、オブジェクトプロパティがあるかをチェックします。機能としてはin 演算子のように動作します。
例
>Reflect.has() の使用
js
Reflect.has({ x: 0 }, "x"); // trueReflect.has({ x: 0 }, "y"); // false// プロトタイプチェーンのプロパティがあるため、true が返るReflect.has({ x: 0 }, "toString");// Proxy with .has() handler methodobj = new Proxy( {}, { has(t, k) { return k.startsWith("door"); }, },);Reflect.has(obj, "doorbell"); // trueReflect.has(obj, "dormitory"); // falseReflect.has は継承されたプロパティについてtrue を返し、これはin 演算子と同様です。
js
const a = { foo: 123 };const b = { __proto__: a };const c = { __proto__: b };// The prototype chain is: c -> b -> aReflect.has(c, "foo"); // true仕様書
| Specification |
|---|
| ECMAScript® 2026 Language Specification> # sec-reflect.has> |