Reflect

Reflect.has

Returns a boolean indicating whether the target object has the specified property, equivalent to the in operator

Syntax

JavaScript
Reflect.has(target, propertyKey)

Parameters

ParameterTypeDescription
targetobjectThe target object to check
propertyKeystring | symbolThe property name to check for

Return Value

true if the property exists, false otherwise

Examples

Basic Usage
const obj = { x: 1, y: 2 }
console.log(Reflect.has(obj, 'x')) // true
console.log(Reflect.has(obj, 'z')) // false
Practical Example
console.log(Reflect.has([], 'length')) // true
console.log(Reflect.has([], 'push')) // true (inherited)
Advanced Usage
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

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.