getOwnPropertyDescriptor()

The static method Reflect.getOwnPropertyDescriptor serves the purpose of obtaining the descriptor for a specific property of an object. This functionality is identical to that of the Object.getOwnPropertyDescriptor method.

Syntax:

Example

Reflect.getOwnPropertyDescriptor (obj,  Key)

Parameters:

Obj : This refers to the object that serves as the target for searching for the property.

Key: This refers to the identifier of the property for which an individual property descriptor is to be obtained.

Return value:

If the specified property is present in the target object, it will return the corresponding property descriptor object. If the property does not exist, it will return undefined.

Exceptions:

A TypeError, if the target is not an Object.

Browser Support:

Chrome 49
Edge 12
Firefox 42
Opera 36

Example 1

Example

const object1 = {
  property1: 22    };
console.log(Reflect.getOwnPropertyDescriptor(object1, 'property2'));
console.log(Reflect.getOwnPropertyDescriptor(object1, 'property1').writable);

Output:

Output

undefined
 true

Example 2

Example

const 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:

Output

234
Undefined
true
true

Example 3

Example

const object1 = {
  property1: 42
};
console.log(Reflect.getOwnPropertyDescriptor(object1, 'property1').value);

console.log(Reflect.getOwnPropertyDescriptor(object1, 'property2'));

console.log(Reflect.getOwnPropertyDescriptor(object1, 'property1').enumerable);

Output:

Output

42
undefined
true

Input Required

This code uses input(). Please provide values below: