Practice
JavaScriptData StructuresReactConcepts
Sign in
← Back to problems

Count Object Keys

Data Structures, Operators & Stringseasy

Course · Section 9: Data Structures, Modern Operators and Strings · Lecture 118: Enhanced Object Literals

Implement `keyCount(obj)` that returns the number of own enumerable keys in `obj`.

Sample tests

Input: keyCount({"a":1,"b":2,"c":3})
Output: 3
Input: keyCount({})
Output: 0

+ 1 hidden test run on Submit.

Hints

Common pitfalls
  • Inherited properties are not included, which is usually intended.

Learning resources

  • MDN: Object.keys
Approach & explanation (try first)

Object.keys(obj).length counts the own enumerable properties.

Loading...
⌘/Ctrl + Enter

Run your code to see results.