Code Lab

Count the keys

EasyObjects3 min

Write a function count(obj) that returns the number of properties of the object obj.

Examples

count({ name: 'John', age: 30 })

Returns 2

count({})

Returns 0

count({ name: '', age: 0 })

Returns 2

An empty string and zero are values of properties too.

Source

Loading the editor...
  1. Inputcount({ name: 'John', age: 30 })
    Expected2
  2. Inputcount({})
    Expected0
  3. Inputcount({ name: '', age: 0 })
    Expected2

Hidden tests run on Submit.