C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Object.getOwnPropertyDescriptor() MethodThe Object.getOwnPropertyDescriptor method allows to query the full information about a property and returns a property descriptor for an own property (that is, one directly present on an object and not in the object's prototype chain) of a given object. Syntax:bject.getOwnPropertyDescriptor(obj, prop) Parameterobj: It is the object in which to look for the property. Prop: It is the name of the property whose description is to be retrieved. Return value:It returns a property descriptor of the given property if it exists on the object. Browser Support:
Example 1const object1 = { property1: 42 } const object2 = { property2: 34 } const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1'); const descriptor2 = Object.getOwnPropertyDescriptor(object2, 'property2'); console.log(descriptor1.enumerable); console.log(descriptor2.enumerable); console.log(descriptor1.value); console.log(descriptor2.value); Output: true true 42 34 Example 2const object1 = { property1: 42 } const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1'); console.log(descriptor1.configurable); console.log(descriptor1.enumerable); console.log(descriptor1.value); Output: true true 42 Example 3const object1 = { property1: 56 } const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1'); console.log(descriptor1.writable); console.log(descriptor1.value); Output: true 56
Next TopicJavaScript Objects
|