InterviewHubPRO
Section Overview
Q285

Question 285 of 521

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

55%
JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

How do you list all properties of an object

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
  const newObject = {
    a: 1,
    b: 2,
    c: 3,
  };

  console.log(Object.getOwnPropertyNames(newObject));
  ["a", "b", "c"];