How to list the properties of a JavaScript object?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
Listing the properties of a JavaScript object sounds simple, but the right API depends on what you mean by "properties." You might want only the object's own enumerable string keys, or you might also need inherited keys, non-enumerable keys, symbol keys, or full key-value pairs.
Object.keys() For Own Enumerable String Keys
The most common answer is Object.keys().
This returns the object's own enumerable string-keyed property names.
Use it when you want the normal properties people think of first and you do not care about inherited members.
Object.entries() For Keys And Values Together
If you want both the property name and value, Object.entries() is often more convenient.
This is a clean pattern for rendering or transforming plain-object data.
for...in Includes Inherited Enumerable Properties
This walks enumerable properties from the object and its prototype chain. Because inherited keys are included, for...in is often not what you want for plain data objects unless you guard it.
That makes the intent explicit.
Non-Enumerable Properties Need Other APIs
Some properties exist on the object but are not enumerable.
Object.keys() does not show hidden, but Object.getOwnPropertyNames() does.
Symbol Keys Need Special Handling
Symbol-keyed properties are invisible to most of the usual string-key APIs.
If you need everything, including symbols, Reflect.ownKeys() is the broadest built-in option.
Choosing The Right Tool
A useful summary is:
- '
Object.keys()for own enumerable string keys' - '
Object.entries()for own enumerable key-value pairs' - '
Object.getOwnPropertyNames()for all own string keys, including non-enumerable ones' - '
Object.getOwnPropertySymbols()for own symbol keys' - '
Reflect.ownKeys()for all own keys, including symbols and non-enumerables'
That is usually the real answer to the question.
Inspecting Property Descriptors
If you also care about writable, enumerable, or configurable flags, use property descriptors.
This is useful for debugging framework objects or metaprogramming, not just normal data display.
This is useful for debugging framework objects or metaprogramming, not just normal data display.
Arrays Are Objects Too
Arrays can be inspected with the same APIs, but remember that you are listing property keys, not just conceptual elements. For a normal array, the numeric indexes are string keys, and there may also be extra custom properties attached.
That distinction matters when utility code is supposed to work on both plain objects and arrays.
Common Pitfalls
The biggest mistake is using for...in and forgetting that it includes inherited enumerable properties. Another is assuming Object.keys() returns every property on the object when it only returns own enumerable string keys. Developers also often forget that symbol keys exist at all, which matters in library code and introspection utilities. Finally, choosing the API without deciding whether inherited or non-enumerable properties matter leads to confusing results.
Summary
- There is no single "list all properties" API that is right for every case.
- '
Object.keys()is the common choice for own enumerable string keys.' - '
for...inincludes inherited enumerable properties and should be used carefully.' - Use descriptor and reflection APIs when non-enumerable or symbol keys matter.
- Pick the API based on the exact definition of "property" your code needs.

