Reflect.has(target, propertyKey) checks whether an object has a property. It returns true or false. It is the function version of the in operator: Reflect.has(obj, "a") does the same as "a" in obj.
The check also looks at the prototype chain. So inherited properties, such as toString, count as well. To check only the object's own properties, use hasOwnProperty() or Object.hasOwn() instead.
Remember
Reflect.has(target, key)
property found (own or inherited) → true
not found → false
Same as: key in target
A property set to undefined still counts
target must be an object, or TypeError
Syntax
Pass an object and the name of the property to look for.
// ECMAScript 2015 (ES6)
Reflect.has(target, propertyKey)
// target : an object
// propertyKey : a string or a symbol
// returns : true or false
// throws : TypeError if target is not an object
Parameters
Parameter
Description
target
Required. The object to look in. If it is not an object, a TypeError is thrown.
propertyKey
Required. The name of the property: a string or a symbol. Numbers are turned into strings.
Return Value
Return Value
Description
true
The object, or something in its prototype chain, has the property.
false
The property is nowhere in the chain.
TypeError (thrown)
target is not an object.
JavaScript Examples
Example 1 — Check if a Property Exists
Look for properties in an object and in an array. A property that holds undefined still counts.
name: true
age: false
nickname: true
Value of nickname: undefined
Position 1: true
Position 5: false
How It Works
Found or not.name is in the object, age is not.
Undefined still exists.nickname holds undefined, but the property is there, so has() returns true. Checking user.nickname === undefined could not tell the difference.
Array positions. An array has properties named "0" and "1", so position 1 exists and position 5 does not.
Example 2 — Own and Inherited Properties
has() looks up the prototype chain. See how that differs from an own-property check.
Symbol key: true
Other symbol: false
Math has PI: true
Array has map: true
String target: TypeError
How It Works
Symbol keys. The same symbol is found. A new Symbol("id") is a different symbol, even with the same description, so it is not found.
Built-ins.Math has the property PI, and every array inherits map from Array.prototype.
Only objects. A string is a primitive, so Reflect.has("abc", "length") throws a TypeError. The in operator also refuses a string on its right side.
Compatibility
Browser & Runtime Support
Reflect.has() is part of ES2015 (ES6), together with the Reflect object. Every current browser and Node.js has it.
✓ ES2015 · Widely supported
Reflect.has()
Supported in Chrome 49+, Edge 12+, Firefox 42+, Safari 10+, Opera 36+ and Node.js 6+. Internet Explorer never got it.
ES2015Standard since
Google Chrome49+ · Desktop & Mobile
Full support
Microsoft Edge12+ · Chromium and legacy
Full support
Mozilla Firefox42+ · Desktop & Mobile
Full support
Apple Safari10+ · macOS & iOS
Full support
Opera36+ · Chromium based
Full support
Samsung InternetRecent versions · Android
Supported
Android WebView49+ · Chromium based
Supported
Node.js6+ · Server runtime
Supported
DenoSupported · JavaScript runtime
Supported
BunSupported · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
Reflect.has()Excellent
Bottom line: Safe to use in every current browser and in Node.js. The only thing to plan for is Internet Explorer, which has no Reflect at all.
Frequently Asked Questions
It checks whether an object has a property and returns true or false. It is the function version of the in operator and it looks at inherited properties too.
Reflect.has() also finds properties that come from the prototype chain, such as toString. hasOwnProperty() and Object.hasOwn() only find properties that belong to the object itself.
Yes. The property exists, so the answer is true, even though its value is undefined. This is the main advantage over checking the value.
Yes. Array items are properties named "0", "1" and so on, so Reflect.has(array, 1) tells you if position 1 exists. It does not tell you whether an item equals a value. Use includes() for that.
A Proxy can intercept the in operator with a has trap. Inside the trap, return Reflect.has(target, key) to answer in the normal way, or return your own answer to hide some properties.