JS Built-ins
ObjectObject.getOwnPropertyNamesbeginner

Object.getOwnPropertyNames() β€” all own string keys

πŸ“– Usage Example
// Get all own property names, including non-enumerable
const obj = { a: 1 }
Object.defineProperty(obj, 'hidden', { value: 2, enumerable: false })
Object.getOwnPropertyNames(obj)   // β†’ ['a', 'hidden']

Use Object.getOwnPropertyNames() to list all own properties including non-enumerable ones, unlike Object.keys().

Object.getOwnPropertyNames()

Object.getOwnPropertyNames(obj) returns an array of all own string-keyed property names, including non-enumerable ones. Unlike Object.keys, it does not filter out non-enumerable properties.

Challenge: Implement getAllNames(obj) that returns all own property names.

getAllNames({ a: 1, b: 2 }) // β†’ ['a', 'b']
πŸ’‘ Hints (1)
  • β€’ `Object.getOwnPropertyNames` is like `Object.keys` but also includes non-enumerable properties.