What is the difference between Reflect.ownKeys(obj) and Object.keys(obj)?
Object.keys() returns an array of strings, which are the object’s own enumerable properties.
Reflect.ownKeys(obj) returns the equivalent of:
Object.getOwnPropertyNames(target).
concat(Object.getOwnPropertySymbols(target))
The Object.getOwnPropertyNames() method returns an array of all properties (enumerable or not) found directly upon a given object.
The Object.getOwnPropertySymbols() method returns an array of all symbol properties found directly upon a given object.
var testObject = {};
Object.defineProperty(testObject, 'myMethod', {
value: function () {
alert("Non enumerable property");
},
enumerable: false
});
//does not print myMethod since it is defined to be non-enumerable
console.log(Object.keys(testObject));
//prints myMethod irrespective of it being enumerable or not.
console.log(Reflect.ownKeys(testObject));
reference : https://stackoverflow.com/questions/34449045/what-is-the-difference-between-reflect-ownkeysobj-and-object-keysobj