TheDeveloperBlog.com

Home | Contact Us

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

Javascript Object getOwnPropertyDescriptors() Method

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

<< Back to JAVASCRIPT

JavaScript Object.getOwnPropertyDescriptors() Method

The Object.getOwnPropertyDescriptors() method returns all own property descriptors of a given object. The difference between getOwnPropertyDescriptors() and getOwnPropertyDescriptor() method is that getOwnPropertyDescriptors() method ignores symbolic properties.

Syntax:

Object.getOwnPropertyDescriptors(obj)

Parameter

obj: It is the object for which to get all own property descriptors.

Return:

This method returns an object which contains all own property descriptors of an object. This method might return an empty object if there are no properties.

Browser Support:

Chrome 54
Edge 15
Firefox 50
Opera 41

Example 1

const object1 = {
  property1: 103
};

const descriptors1 = Object.getOwnPropertyDescriptors(object1);
console.log(descriptors1.property1.writable);
console.log(descriptors1.property1.value);

Output:

103

Example 2

const object1 = {
  property1: 22
};
const descriptors1 = Object.getOwnPropertyDescriptors(object1);
console.log(descriptors1.property1.value);
console.log(descriptors1.property1);
console.log(descriptors1.property1.writable);

Output:

[object Object] {
  configurable: true,
  enumerable: true,
  value: 22,
  writable: true
}
true

Example 3

const object1 = {
  property1: 42
};
const object2 = {
  property2: 23
};

const descriptors1 = Object.getOwnPropertyDescriptors(object1);
const descriptors2 = Object.getOwnPropertyDescriptors(object2);
console.log(descriptors1.property1.writable);
console.log(descriptors1.property1.value,descriptors2.property2.value);

Output:

true
42 
23

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