JS Built-ins
ObjectObject.keysbeginner

Object.keys() β€” array-like objects

πŸ“– 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() β€” arrays and array-like objects

Object.keys() also works on arrays, returning the index strings as keys.

Challenge: Use Object.keys() on an array to get its index keys.

πŸ’‘ Hints (1)
  • β€’ Array indices are strings in JavaScript