Testing them out in a real simple case yields the same output:
const obj = {a: 5, b: 5};
console.log(Reflect.ownKeys(obj));
console.log(Object.keys(obj));
// Re
Object.keys
returns only enumerable string keys; Reflect.ownKeys
returns both string and symbol keys regardless of their enumerability. Both operate on own properties only.Object.keys
returns an empty array if the argument is not an object and not null
or undefined
(e.g. Object.keys(1)
), whereas Reflect.ownKeys
throws a TypeError
.Reflect.ownKeys
was introduced with ES6 and is not supported in older JavaScript engines.