Count Object Fields
Counts the number of enumerable own properties in an object.
countObjectFields
The countObjectFields function counts the number of enumerable own properties in a given object. It safely handles null and undefined inputs by returning 0.
Function Signature
function countObjectFields<T>(obj: T): numberParameters
obj(T): The object to count properties of.
Return Value
number: The count of enumerable own properties, or0if the object isnull,undefined, or not a valid object.
Example Usage
playground.ts
Notes
- This function only counts enumerable own properties (identical behavior to
Object.keys()). - Inherited properties from the prototype chain are not counted.
- Symbol-keyed properties are not counted.
Last updated: Sun, Jun 14, 2026 07:06:16AM (UTC)
