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.jsonThis 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