Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript

What is Object.getOwnPropertyDescriptors() in Javascript?

Kainat Asif

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

The Object.getOwnPropertyDescriptors() method returns all the property descriptors of the properties of an object. getOwnPropertyDescriptors() is declared as follows:

Object.getOwnPropertyDescriptors(obj)
  • obj: The object whose property descriptors are required.

Return value

The getOwnPropertyDescriptors() method returns an object that contains all the property descriptors of the object obj.

Note: If an object has no properties, the getOwnPropertyDescriptors() method returns an empty object.

Browser compatibility

The getOwnPropertyDescriptors() method is supported by the following browsers:

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

Note: The getOwnPropertyDescriptors() method is not supported by Internet Explorer.

Example

Consider the code snippet below, which demonstrates the use of the getOwnPropertyDescriptors() method:

var obj = { property1: 'foo1',
property2: 'foo2',
property3: 'foo3'
}
var objDescriptors = Object.getOwnPropertyDescriptors(obj)
console.log("obj has properties: ", objDescriptors)

Explanation

An object obj is declared in line 1 with three properties, property1, property2, and property3. The getOwnPropertyDescriptors() method is called on obj in line 6. The method returns an object that contains the property descriptors of obj. This object is assigned to objDescriptors in line 6.

RELATED TAGS

javascript

CONTRIBUTOR

Kainat Asif
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

Keep Exploring