Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Reflect
  6. has()

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 ⁨September 2016⁩.

TheReflect.has() static method is like thein operator, butas a function.

Try it

const object = {  property1: 42,};console.log(Reflect.has(object, "property1"));// Expected output: trueconsole.log(Reflect.has(object, "property2"));// Expected output: falseconsole.log(Reflect.has(object, "toString"));// Expected output: true

Syntax

js
Reflect.has(target, propertyKey)

Parameters

target

The target object in which to look for the property.

propertyKey

The name of the property to check.

Return value

ABoolean indicating whether or not thetarget has the property.

Exceptions

TypeError

Thrown iftarget is not an object.

Description

Reflect.has() provides the reflective semantic of checking if a property is in an object. That is,Reflect.has(target, propertyKey) is semantically equivalent to:

js
propertyKey in target;

Reflect.has() invokes the[[HasProperty]]object internal method oftarget.

Examples

Using Reflect.has()

js
Reflect.has({ x: 0 }, "x"); // trueReflect.has({ x: 0 }, "y"); // false// returns true for properties in the prototype chainReflect.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"); // false

Reflect.has returnstrue for any inherited properties, like thein operator:

js
const a = { foo: 123 };const b = { __proto__: a };const c = { __proto__: b };// The prototype chain is: c -> b -> aReflect.has(c, "foo"); // true

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-reflect.has

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp