JS Built-ins
ObjectObject.keysbeginner

Object.keys() β€” basic usage

πŸ“– Usage Example
// Get array of own enumerable property names
const obj = { a: 1, b: 2, c: 3 }
Object.keys(obj)   // β†’ ['a', 'b', 'c']

Use Object.keys() to get an array of an object's own enumerable property names for iteration or counting.

Object.keys()

Object.keys(obj) returns an array of the object's own enumerable string-keyed property names, in the same order as a for...in loop (excluding prototype properties).

Challenge: Implement getKeys(obj) that returns an array of the object's own enumerable keys.

πŸ’‘ Hints (1)
  • β€’ Object.keys only returns own enumerable string-keyed properties