C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Reflect.ownKeys() MethodThe static Reflect.ownKeys() method returns an array whose values represents the keys of the properties of a provided object. It ignores the inherited properties. Syntax:Reflect.ownKeys(obj) Parameters:Obj: It is the target object from which to get the own keys. Return value:IT returns an Array of the target object's own property keys. Exceptions:A TypeError, if the target is not an Object. Browser Support:
Example 1const obj = {a: 5, b: 5}; console.log(Reflect.ownKeys(obj)); console.log(Object.keys(obj)); Output: ["a", "b"] ["a", "b"] Example 2const obj = {a: 5, b: 5}; const obj1 = {a: 5, b: 5, c:7}; console.log(Reflect.ownKeys(obj)); console.log(Object.keys(obj1)); console.log(Reflect.ownKeys(obj1)); Output: ["a", "b"] ["a", "b", "c"] ["a", "b", "c"] Example 3var obj1 = Object.create({}, { hoo: { value: function() { return this.hoo; } } }); console.log(Object.keys(obj1)); console.log(Reflect.ownKeys(obj1)); Output: [] ["hoo"]
Next TopicJavaScript Reflect
|