TheDeveloperBlog.com

Home | Contact Us

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

Javascript Object getOwnPropertyDescriptor() Method

Javascript Object getOwnPropertyDescriptor() Method with example on javascript, object, getOwnPropertyDescriptor(), getOwnPropertyDescriptors(), defineProperties(), defineProperty(), entries(), freeze(), javascript tutorial, javascript array etc.

<< Back to JAVASCRIPT

JavaScript Object.getOwnPropertyDescriptor() Method

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

Parameter

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

Chrome 4
Edge Yes
Firefox 12
Opera 4

Example 1

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

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

const object1 = {
  property1: 56
}
const descriptor1 = Object.getOwnPropertyDescriptor(object1, 'property1');
console.log(descriptor1.writable);
console.log(descriptor1.value);

Output:

true
56

Next TopicJavaScript Objects




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