C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Reflect.getOwnPropertyDescriptor() MethodThe static Reflect.getOwnPropertyDescriptor() method is used to retrieve the descriptor of an object's property. It is same as the Object.getOwnPropertyDescriptor method. Syntax:Reflect.getOwnPropertyDescriptor (obj, Key) Parameters:Obj: It is the target object in which to look for the property. Key: It is the name of the property to get an own property descriptor for. Return value:It returns the property descriptor object if the property exists in the given target object. Otherwise, it returns undefined. Exceptions:A TypeError, if the target is not an Object. Browser Support:
Example 1const object1 = { property1: 22 }; console.log(Reflect.getOwnPropertyDescriptor(object1, 'property2')); console.log(Reflect.getOwnPropertyDescriptor(object1, 'property1').writable); Output: undefined true Example 2const object1 = { property1: 234 }; const hh = {p:4}; console.log(Reflect.getOwnPropertyDescriptor(object1, 'property1').value); console.log(Reflect.getOwnPropertyDescriptor(object1, 'property2')); console.log(Reflect.getOwnPropertyDescriptor(object1, 'property1').writable); console.log ( Reflect.getOwnPropertyDescriptor ( hh , "yyy" ) === undefined ); Output: 234 Undefined true true Example 3const object1 = { property1: 42 }; console.log(Reflect.getOwnPropertyDescriptor(object1, 'property1').value); console.log(Reflect.getOwnPropertyDescriptor(object1, 'property2')); console.log(Reflect.getOwnPropertyDescriptor(object1, 'property1').enumerable); Output: 42 undefined true
Next TopicJavaScript Reflect
|