Object.entriesLoading saved progress…

Object.entries

Object.entries turns an object into an array of its [key, value] pairs — the shape you need to iterate an object with array tools, map over its fields, or feed it into a Map. It returns only the object's own, enumerable, string-keyed properties.

Implement objectEntries(obj). Return one [key, value] pair per own enumerable string key, in the standard property order. Skip anything inherited from the prototype, anything non-enumerable, and any symbol keys.

Signature

function objectEntries(obj) {
  // returns an array of [key, value] pairs for obj's own enumerable
  // string-keyed properties, e.g. { a: 1 } -> [['a', 1]]
}

Examples

objectEntries({ a: 1, b: 2 }); // [['a', 1], ['b', 2]]
// Integer-like keys come first, ascending; then string keys in order:
objectEntries({ 2: 'a', 1: 'b', x: 'c' }); // [['1', 'b'], ['2', 'a'], ['x', 'c']]

Notes

  • Own only — properties inherited from the prototype chain are excluded. Only what the object itself holds counts.
  • Enumerable only — a property defined with enumerable: false is skipped.
  • String keys only — symbol-keyed properties never appear in entries.
  • Key order — integer-like keys in ascending numeric order first, then the remaining string keys in insertion order. This is JavaScript's standard own-key ordering.
  • Keys are strings — even a numeric key like 7 comes back as the string '7'.
Loading editor…