TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

JavaScript Reflect getOwnPropertyDescriptor() Method

JavaScript Reflect getOwnPropertyDescriptor() Method with examples on javascript reflect methods, apply() construct(), defineProperty() method, deleteProperty(), get(), getOwnPropertyDescriptor(), getPrototypeOf(), has(), isExtensible(), ownKeys(), setPrototypeOf() etc.

<< Back to JAVASCRIPT

JavaScript Reflect.getOwnPropertyDescriptor() Method

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

Chrome 49
Edge 12
Firefox 42
Opera 36

Example 1

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

Output:

undefined
 true

Example 2

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:

234
Undefined
true
true

Example 3

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:

42
undefined
true 
Next TopicJavaScript Reflect




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf