Course contentsShow
← JavaScript
Lesson 645 of 2,72315. ObjectsFree lesson

Reflect.ownKeys() for All Own Property Keys

Reflect.ownKeys() returns both string and symbol keys, enumerable or not, in one array.

Reflect.ownKeys() for All Own Property Keys

You'll learn how to get every single own property key from an object, regardless of type or enumerability.

What Makes Reflect.ownKeys() Different?

You've seen several methods for inspecting object properties: Object.keys() only gets enumerable string keys, Object.getOwnPropertyNames() gets all string keys (enumerable or not), and Object.getOwnPropertySymbols() gets only symbol keys. Each method gives you part of the picture.

Reflect.ownKeys() is the complete solution—it returns all own property keys in a single array, including:

  • String keys (enumerable and non-enumerable)
  • Symbol keys (enumerable and non-enumerable)

Think of it like requesting a full inventory: while other methods filter by category, Reflect.ownKeys() gives you everything in one list.

How It Works

const sym = Symbol('mySymbol');

const obj = {
  visible: 'I show up in for...in',
  [sym]: 'I am a symbol property'
};

Object.defineProperty(obj, 'hidden', {
  value: 'Not enumerable',
  enumerable: false
});

console.log(Reflect.ownKeys(obj));
// ['visible', 'hidden', Symbol(mySymbol)]

// Compare with other methods:
console.log(Object.keys(obj));                    // ['visible']
console.log(Object.getOwnPropertyNames(obj));     // ['visible', 'hidden']
console.log(Object.getOwnPropertySymbols(obj));   // [Symbol(mySymbol)]

Notice how Reflect.ownKeys() captures everything in one call, while the others each miss something.

When to Use It

Use Reflect.ownKeys() when you need absolute completeness—for deep cloning, serialization, or debugging where you can't afford to miss any properties.

Key Takeaway: Reflect.ownKeys() returns all own property keys (strings and symbols, enumerable or not) in a single array—it's your one-stop method for complete property inspection.