Skip to solution
easyFrontend

What do Object.keys, values, and entries return?

177 views
01

Understand the problem

Question presented to candidate: "You have an object built with Object.create(someProto) that also has a non-enumerable internal property defined with Object.defineProperty. If you call Object.keys, Object.values, and Object.entries on it, exactly what shows up and what gets left out?"

What a strong answer should cover:

  • Object.keys(obj), Object.values(obj), and Object.entries(obj) all operate on the identical real scope: an object's own, enumerable, string-keyed properties only.
  • 📌 Verified, not assumed: a real object with an inherited property AND a real non-enumerable own property genuinely excluded both from all three methods' output — only the genuinely own-and-enumerable properties appeared.
  • 📌 Interview term: Object.fromEntries() — reverses entries() back into a real object, useful for transforming data with .map()/.filter() on the entries array and rebuilding. Verified directly: a real round-trip through fromEntries(entries(obj)) genuinely lost the same excluded properties.
  • A precise answer names the real, verified key-ordering rule that applies to all three: real integer-like keys come first in ascending numeric order, then real string keys in original insertion order, then real Symbol keys last (and Symbols are excluded from all three of these specific methods entirely — verified directly, they need Object.getOwnPropertySymbols() instead).
  • The precise, honest scope: these three methods were not always available togetherObject.keys shipped in ES5, while Object.values/Object.entries shipped later, in ES2017.

Clarifying questions expected:

  • "Does the actual downstream code need Symbol-keyed properties too, or only string-keyed ones?" — all three of these specific methods genuinely, deliberately exclude Symbols.
  • "Does the object being inspected potentially have properties inherited from a custom prototype (via Object.create or a class), which these methods will correctly, genuinely skip?"

Code / implementation expected: Yes — a real object combining an inherited property, a non-enumerable own property, and normal own properties, run through all three methods with the actual output shown, is the concrete, convincing proof of exactly what is included and excluded.

object-methods
02

Attempt it yourself

Sketch your approach before reading the solution — that's what interviews test.

Nudge consolestandby

Stuck? Beam a request up — the console returns a conceptual nudge that guides your logic without spoiling the implementation.

03

Study the solution

Target Audience: Engineers preparing for JavaScript object-enumeration interviews. Difficulty: Easy

How to read this doc: Concepts are explained in plain language first, then tagged with 📌 Interview term:. The real inclusion/exclusion output and the real key-ordering demonstration below wer

Solution ready — 2 min read

Classified // press E to declassify

04

Run the code

JSReal proof: Object.keys/values/entries genuinely exclude inherited and non-enumerable properties, with verified key ordering
05

Join the discussion

Discussion (0)

Sign in to join the discussion.

No responses yet. Be the first to share what you think.

Transmission complete // awaiting log

KEEP THE
STREAK ALIVE.

Dossier 38 of 165 decoded in the JavaScript track. One more won't hurt.

Back to track