JS Coding Questions Logo
JS Coding Questions
#282💼 Interview💻 Code

How do you get property descriptors of an object

Advertisement

728x90

You can use the Object.getOwnPropertyDescriptors() method which returns all own property descriptors of a given object. The example usage of this method is below,

javascript
1const newObject = {
2  a: 1,
3  b: 2,
4  c: 3,
5  };
6
7const descriptorsObject = Object.getOwnPropertyDescriptors(newObject);
8
9console.log(descriptorsObject.a.writable); //true
10
11console.log(descriptorsObject.a.configurable); //true
12
13console.log(descriptorsObject.a.enumerable); //true
14
15console.log(descriptorsObject.a.value); // 1

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 26

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
282of476