back to the lesson

Count properties

importance: 5

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

let user = {
  name: 'John',
  age: 30

alert( count(user) ); // 2

Try to make the code as short as possible.

P.S. Ignore symbolic properties, count only “regular” ones.

Open a sandbox with tests.

function count(obj) {
  return Object.keys(obj).length;

Open the solution with tests in a sandbox.