Reflect

Reflect.ownKeys

Returns an array of the target object's own property keys including non-enumerable and symbol properties

Syntax

JavaScript
Reflect.ownKeys(target)

Parameters

ParameterTypeDescription
targetobjectThe target object to get the keys from

Return Value

An Array of the target's own property keys (strings and symbols)

Examples

Basic Usage
const obj = { a: 1, b: 2 }
const sym = Symbol('c')
;(obj as any)[sym] = 3
console.log(Reflect.ownKeys(obj)) // ['a', 'b', Symbol(c)]
Practical Example
const obj = Object.create(null, {
  visible: { value: 1, enumerable: true },
  hidden: { value: 2, enumerable: false }
})
console.log(Reflect.ownKeys(obj)) // ['visible', 'hidden']
Advanced Usage
function getAllKeys(obj: object): (string | symbol)[] {
  return Reflect.ownKeys(obj)
}

Understanding Reflect.ownKeys

The Reflect.ownKeys method in JavaScript returns an array of the target object's own property keys including non-enumerable and symbol properties. 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.ownKeys(target). It accepts 1 parameter: target. When called, it returns an array of the target's own property keys (strings and symbols). Understanding when and how to use ownKeys() helps you write more expressive, readable code.

Common use cases for Reflect.ownKeys include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like reflect-has, reflect-get, object-keys, enabling you to chain operations together for complex data manipulation pipelines.

Browser support for Reflect.ownKeys 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.