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

How do you list all properties of an object

Advertisement

728x90

You can use the Object.getOwnPropertyNames() method which returns an array of all properties found directly in a given object. Let's see the usage of this in an example below:

javascript
1const newObject = {
2  a: 1,
3  b: 2,
4  c: 3,
5  };
6
7console.log(Object.getOwnPropertyNames(newObject));
8["a", "b", "c"];

Advertisement

Responsive Ad
🎯 Practice NowRelated Challenge

JavaScript Coding Exercise 25

Test your knowledge with this interactive coding challenge.

Start Coding

Advertisement

728x90
281of476