Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Reflect.ownKeys — all own property keys

Reflect.ownKeys(target) requires an object. For an ordinary object, it returns an array of all own string and symbol keys, including non-enumerable ones, and excludes inherited properties. A Proxy's ownKeys trap can change which keys are returned.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

Reflect.ownKeys(target)

Reflect.ownKeys(target) creates a new array of keys. For an ordinary object, the array contains the keys of all own properties of target, both enumerable and non-enumerable. Its elements are strings or symbols, not property values. It does not search the prototype chain. A non-object argument, including null or a string, causes a TypeError; it is not automatically wrapped in an object.

For ordinary objects, array-index keys come first in ascending numeric order, followed by other strings in property creation order, then symbols in property creation order. Thus "2" precedes "10" even if they were added in the opposite order; the keys themselves are still strings.

In contrast, Object.keys returns only enumerable string keys. Object.getOwnPropertyNames includes own string keys, while Object.getOwnPropertySymbols includes own symbols. Use Reflect.ownKeys when you need both kinds of keys without filtering by enumerability.

The method invokes the internal [[OwnPropertyKeys]] operation. For a Proxy, this can trigger the ownKeys trap, so it can execute user code, throw an exception, or return keys in a different permitted order from that of an ordinary object. The trap can also change which keys are returned: if the proxy's target is extensible, the trap can omit keys of configurable own properties or report extra keys for which the target has no own property descriptor. It must include keys of non-configurable own properties, and if the target is not extensible, the returned key set must exactly match the target's own key set. Do not assume ordinary ordering for every exotic object. This is an ECMAScript language API; merely having Node 24 in a repository does not establish support in a target browser.

Examples

const tag = Symbol("tag");
const target = Object.create({ inherited: true });
target["10"] = "ten";
target["2"] = "two";
target.name = "Ada";
Object.defineProperty(target, "hidden", { value: 42 });
target[tag] = "metadata";

const keys = Reflect.ownKeys(target);
console.log(keys.map(key => String(key)).join(" | "));
console.log(keys[keys.length - 1] === tag);

Result

2 | 10 | name | hidden | Symbol(tag)
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources