JS Built-ins
ObjectObject.entriesbeginner

Object.entries() β€” only own enumerable properties

πŸ“– Usage Example
// Get [key, value] pairs of an object
const obj = { a: 1, b: 2 }
Object.entries(obj)   // β†’ [['a', 1], ['b', 2]]

Use Object.entries() to get an array of [key, value] pairs for iterating over an object's own enumerable properties.

Object.entries() β€” own properties only

Object.entries only returns own and enumerable properties β€” inherited or non-enumerable ones are excluded.

Challenge: Implement countEntries(obj) that returns the number of own enumerable entries.

countEntries({ a: 1, b: 2 }) // β†’ 2
πŸ’‘ Hints (2)
  • β€’ `Object.entries` skips inherited and non-enumerable properties.
  • β€’ Use `.length` on the result to count.