Reflect.has
Returns a boolean indicating whether the target object has the specified property, equivalent to the in operator
Syntax
Reflect.has(target, propertyKey)Parameters
| Parameter | Type | Description |
|---|---|---|
| target | object | The target object to check |
| propertyKey | string | symbol | The property name to check for |
Return Value
true if the property exists, false otherwise
Examples
const obj = { x: 1, y: 2 }
console.log(Reflect.has(obj, 'x')) // true
console.log(Reflect.has(obj, 'z')) // falseconsole.log(Reflect.has([], 'length')) // true
console.log(Reflect.has([], 'push')) // true (inherited)const handler: ProxyHandler<object> = {
has(target, prop) {
console.log(`Checking ${String(prop)}`)
return Reflect.has(target, prop)
}
}Understanding Reflect.has
The Reflect.has method in JavaScript returns a boolean indicating whether the target object has the specified property, equivalent to the in operator. It belongs to the Reflect object and is one of the most widely used methods for working with reflect values in modern JavaScript and TypeScript applications.
The method signature is Reflect.has(target, propertyKey). It accepts 2 parameters: target, propertyKey. When called, it returns true if the property exists, false otherwise. Understanding when and how to use has() helps you write more expressive, readable code.
Common use cases for Reflect.has include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like reflect-get, reflect-set, reflect-ownkeys, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Reflect.has is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
Reflect.getGets the value of a property on an object, similar to target[propertyKey] but as a function
Reflect.setSets the value of a property on an object, similar to target[propertyKey] = value but as a function
Reflect.ownKeysReturns an array of the target object's own property keys including non-enumerable and symbol properties
More Reflect Methods
Other methods in the Reflect object
Related Tools
More Reflect Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.