Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

JavaScript | Object.getOwnPropertyDescriptors() Method

  • Last Updated : 22 Dec, 2021

The Object.getOwnPropertyDescriptors() method in JavaScript is standard built-in objects which returns all property descriptors of a given object.

Syntax:

Object.getOwnPropertyDescriptors( obj )

Parameters: This method accepts single parameter as mentioned above and described below:

  • obj: This parameter holds the object for which all own property descriptors are to be get.

Return value: This method returns object containing all own property descriptors of an object. This method may return an empty object for the object having no properties.

Below examples illustrate the Object.getOwnPropertyDescriptors() method in JavaScript:

Example 1:




<script>
const geeks1 = {  
  prop1: "GeeksforGeeks" 
}  
const geeks2 = {  
  prop2: "Best Platform"
  prop3: "And Computer science portal" 
const descriptor1 = Object.getOwnPropertyDescriptors(geeks1);  
const descriptor2 = Object.getOwnPropertyDescriptors(geeks2);  
console.log(descriptor1.prop1.enumerable);  
console.log(descriptor2.prop2.enumerable);  
console.log(descriptor1.prop1.value);  
console.log(descriptor2.prop2.value); 
console.log(descriptor2.prop3.value); 
</script>

Output:

true
true
"GeeksforGeeks"
"Best Platform"
"And Computer science portal"

Example 2:




<script>
const geeks1 = {  
  prop1: 22  
};  
const descriptors1 = 
    Object.getOwnPropertyDescriptors(geeks1);  
  
console.log(descriptors1.prop1.value);  
console.log(descriptors1.prop1);  
console.log(descriptors1.prop1.writable); 
  
const geeks2 = {  
  prop2: " getOwnPropertyDescriptors" 
};  
    
const descriptors2 = 
    Object.getOwnPropertyDescriptors(geeks2);  
  
console.log(descriptors2.prop2.writable);  
console.log(descriptors2.prop2.value);  
</script>

Output:

22
Object { value: 22, writable: true, enumerable: true, configurable: true }
true
true
" getOwnPropertyDescriptors"

Supported Browsers: The browsers supported by Object.getOwnPropertyDescriptors() method are listed below:

  • Google Chrome 54 and above
  • Firefox 50 and above
  • Opera 41 and above
  • Safari 10 and above
  • Edge 15 and above

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!