JavaScript Reflect.ownKeys() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
Static method

Definition

Reflect.ownKeys(target) returns an array of all the own keys of an object. It includes string keys and symbol keys, and it includes properties that are hidden from loops (non-enumerable).

That makes it more complete than Object.keys(), which only lists enumerable string keys. Inherited properties are never included. The keys come in a fixed order: whole numbers first, then strings in the order they were added, then symbols.

Remember
Reflect.ownKeys(target)

returns an array with:
  1) integer keys, smallest first
  2) string keys, in order of creation
  3) symbol keys, in order of creation

includes hidden (non-enumerable) keys
target must be an object, or TypeError

Syntax

Pass an object and loop over the returned array.

JavaScript
const user = { name: "Ann", age: 30 };

const keys = Reflect.ownKeys(user);

console.log(keys.join(", "));   // name, age
console.log(keys.length);       // 2
CallWhat it does
Reflect.ownKeys(obj)Every own key: strings, numbers (as strings) and symbols.
Reflect.ownKeys([10, 20])For an array: "0", "1" and "length".
Object.keys(obj)Only enumerable string keys. A shorter list.
Object.getOwnPropertySymbols(obj)Only the symbol keys.

A standard JavaScript static method (ES2015) of the Reflect object: call it as Reflect.ownKeys(). No import required. Siblings: Reflect.apply(), Reflect.construct(), Reflect.defineProperty(), Reflect.deleteProperty(), Reflect.get(), Reflect.getOwnPropertyDescriptor(), Reflect.getPrototypeOf(), Reflect.has(), Reflect.isExtensible(), Reflect.preventExtensions(), Reflect.set(), Reflect.setPrototypeOf().

Library declarations
JavaScript
// ECMAScript 2015 (ES6)
Reflect.ownKeys(target)

// target : an object
// returns: an array of strings and symbols
// throws : TypeError if target is not an object

Parameters

ParameterDescription
targetRequired. The object whose keys you want. If it is not an object, a TypeError is thrown.

Return Value

Return ValueDescription
ArrayAll own keys. Numbers are returned as strings, such as "1". Symbols are returned as symbols.
TypeError (thrown)target is not an object.

JavaScript Examples

Example 1 — List the Keys and Their Order

See the order of the keys: numbers first, then names in the order they were added.

JavaScript
const obj = { b: 1, a: 2, 2: "x", 1: "y" };
const keys = Reflect.ownKeys(obj);

console.log("Keys: " + keys.join(", "));
console.log("Count: " + keys.length);
console.log("Type of 1: " + typeof keys[0]);

console.log("Array keys: " + Reflect.ownKeys([10, 20]).join(", "));
Try It Yourself

How It Works

  1. Numbers first. The keys 1 and 2 come first, smallest first. The names follow in the order they were written: b before a.
  2. Numbers become text. Property keys are always strings, so the first key is "1" and its type is "string".
  3. Arrays. An array has the keys "0" and "1" for its items, and also "length".

Example 2 — Symbols and Hidden Keys

Compare Object.keys() with Reflect.ownKeys() for an object that has a hidden property and a symbol.

JavaScript
const tag = Symbol("tag");
const item = { name: "Pen", [tag]: "office" };
Object.defineProperty(item, "secret", { value: 42 });

console.log("Object.keys: " + Object.keys(item).join(", "));
console.log("Reflect.ownKeys: " + Reflect.ownKeys(item).map(String).join(", "));

const symbols = Reflect.ownKeys(item).filter((key) => typeof key === "symbol");
console.log("Symbol keys: " + symbols.length);
console.log("Hidden but readable: " + item.secret);
Try It Yourself

How It Works

  1. Object.keys is short. It lists only enumerable string keys, so it finds just name.
  2. ownKeys is complete. It also finds secret (hidden, because defineProperty() made it non-enumerable) and the symbol, which comes last. map(String) turns the symbol into readable text.
  3. Filter by type. typeof key === "symbol" picks out the symbol keys. The hidden property can still be read directly.

Example 3 — Own Keys Only and Errors

Inherited keys and class methods are not listed. A primitive value throws. The catch block prints the error type only.

JavaScript
class Pet {
  constructor() {
    this.name = "Rex";
  }
  speak() {
    return "Woof";
  }
}

const rex = new Pet();
console.log("Instance keys: " + Reflect.ownKeys(rex).join(", "));
console.log("Prototype keys: " + Reflect.ownKeys(Pet.prototype).join(", "));

const child = Object.create({ inherited: 1 });
console.log("Inherited keys listed: " + Reflect.ownKeys(child).length);

try {
  Reflect.ownKeys("abc");
} catch (err) {
  console.log("String target: " + err.name);
}
Try It Yourself

How It Works

  1. Instance data only. The instance owns name. The method speak lives on the prototype, so it is not listed for the instance.
  2. The prototype has its own keys. Asking for the keys of Pet.prototype shows constructor and speak.
  3. Inherited keys are skipped. The child has no own keys, so the list is empty. A string is not an object, so the last call throws a TypeError.

Browser & Runtime Support

Reflect.ownKeys() is part of ES2015 (ES6), together with the Reflect object. Every current browser and Node.js has it.

✓ ES2015 · Widely supported

Reflect.ownKeys()

Supported in Chrome 49+, Edge 12+, Firefox 42+, Safari 10+, Opera 36+ and Node.js 6+. Internet Explorer never got it.

ES2015 Standard since
Google Chrome 49+ · Desktop & Mobile
Full support
Microsoft Edge 12+ · Chromium and legacy
Full support
Mozilla Firefox 42+ · Desktop & Mobile
Full support
Apple Safari 10+ · macOS & iOS
Full support
Opera 36+ · Chromium based
Full support
Samsung Internet Recent versions · Android
Supported
Android WebView 49+ · Chromium based
Supported
Node.js 6+ · Server runtime
Supported
Deno Supported · JavaScript runtime
Supported
Bun Supported · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
Reflect.ownKeys() 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 returns an array with every own key of an object: string keys, number keys (as strings) and symbol keys, including hidden (non-enumerable) properties. Inherited keys are not included.
Object.keys() lists only enumerable string keys. Reflect.ownKeys() lists all own keys, including symbols and non-enumerable properties such as the length of an array.
First whole-number keys from smallest to largest, then string keys in the order they were created, then symbol keys in the order they were created.
If the object has a symbol key, the array contains a symbol, and a symbol cannot be turned into text automatically. Use keys.map(String).join(", ") or filter the symbols out first.
A Proxy can change the list of keys with an ownKeys trap. Inside the trap, Reflect.ownKeys(target) gives the normal list, which you can then filter, for example to hide keys that start with an underscore.

Next: Reflect.preventExtensions()

Learn how to stop new properties from being added to an object.

Reflect.preventExtensions() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

12 people found this page helpful