QuickSnip LogoA light blue logo with a thunderbolt in bracketsQuickSnip

Count Properties in Object

Counts the number of own properties in an object.

  • object
  • count
  • properties

Install

npx shadcn@latest add https://quicksnip.dev/r/count-properties-in-object.json

This snippet is not verified yet. Review it before use, or help verify it.

Code

function countProperties(obj) {
  return Object.keys(obj).length;
}

Usage

const obj = { a: 1, b: 2, c: 3 };
countProperties(obj); // Returns: 3