For an ordinary, non-null object, check Object.keys(value).length === 0. This returns true when the object has no own, enumerable, string-keyed properties. It does not mean the object has no properties of every kind.
Check an ordinary object
Object.keys() returns the object’s own enumerable string-keyed property names. Comparing the resulting array’s length with zero is the concise default for an object literal:
As an Amazon Associate I earn from qualifying purchases.
function isEmptyObject(value: object): boolean {
return Object.keys(value).length === 0;
}
This function assumes it receives a non-null object. The check is JavaScript runtime behavior; the TypeScript annotation describes the intended input but does not inspect its properties.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Decide what “empty” means
The Object.keys() check counts only own, enumerable, string-keyed properties. It ignores inherited properties, own non-enumerable properties, and symbol keys. For example, an object with only a non-enumerable property still produces an empty array from Object.keys().
#1 Best Overall
Choose the API that matches the properties you want to count:
| Check | Properties counted |
|---|---|
Object.keys(value).length === 0 |
Own, enumerable, string-keyed properties |
Object.getOwnPropertyNames(value).length === 0 |
All own string-keyed properties, including non-enumerable ones |
Reflect.ownKeys(value).length === 0 |
All own string and symbol keys, including non-enumerable ones |
Object.entries(value).length === 0 |
Own, enumerable, string-keyed properties, like Object.keys() |
Handle null and undefined deliberately
Object.keys() should not be called with null or undefined. If either may reach the helper, decide whether nullish input should count as empty or non-empty, then encode that policy:
Rank #2
- TypeScript implements a superset of syntax for strictly typed development, facilitating deep static analysis and enhanced development environment integration. The compiler translates source into standard script formats, ensuring parity across any runtime.
- TypeScript is ideal for front-end developers, full-stack engineers, and software architects who build large-scale web applications. It serves those looking to improve code excellence, reduce bugs through static checking, and maintain complex projects more.
- Lightweight, Classic fit, Double-needle sleeve and bottom hem
function isEmptyObject(value: object | null | undefined): boolean {
return value != null && Object.keys(value).length === 0;
}
In this version, null and undefined return false. To treat them as empty instead, use value == null || Object.keys(value).length === 0. Choose one behavior based on what the caller means by “empty”; these are application policies, not interchangeable definitions.
Use collection-specific checks for Map and Set
A Map or Set can hold entries without exposing them as ordinary enumerable object properties. Check its collection contents with size:
const mapIsEmpty = map.size === 0;
const setIsEmpty = set.size === 0;
Similarly, an Object.keys() check is not automatically a useful emptiness test for arrays or class instances. Select a check that reflects the runtime value and the data you intend to count.
Why the TypeScript type does not answer the question
TypeScript’s object type describes non-primitive values; it does not guarantee that a value is a plain object literal or define what “empty” means for it. At runtime, JavaScript examines the actual value. Use the relevant property-key check for ordinary objects and size for Map and Set.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →




