JS Built-ins
ControlFlowintermediate

Control Flow β€” for...in: iterate over object keys

for...in iterates enumerable property keys

for...in iterates over all enumerable string keys of an object (own + inherited). Usually combined with hasOwnProperty for safety.

Challenge: Write collectOwnKeys(obj) that returns a sorted array of the object's own enumerable keys using for...in + hasOwnProperty.

πŸ’‘ Hints (1)
  • β€’ Use Object.prototype.hasOwnProperty.call(obj, key) to skip inherited properties