Skip to content

isEmpty

Checks if a plain object has no own enumerable string-keyed properties. null and undefined are treated as empty objects and return true.

Symbol-keyed properties are not counted. Use Object.getOwnPropertySymbols separately if symbol keys matter for your use case.

Available since v2.0.3

import { isEmpty } from '@helpers4/object';
// or, from the all-in-one package (same code, one install):
import { isEmpty } from 'helpers4/object';
isEmpty(value: Record<PropertyKey, unknown> | null | undefined): boolean
ParameterTypeDescription
valueRecord<PropertyKey, unknown> | null | undefinedThe object to check

boolean — true if the object has no own enumerable string-keyed properties, or if value is null/undefined

Check if an object has no own string-keyed properties

Section titled “Check if an object has no own string-keyed properties”

Returns true for {}. Symbol-keyed properties are not counted.

isEmpty({})              // => true
isEmpty({ a: 1 })        // => false
isEmpty({ a: undefined }) // => false  (key exists even if value is undefined)

An object with only symbol-keyed properties is considered empty.

const sym = Symbol('x');
const obj = { [sym]: 1 };
isEmpty(obj) // => true  (only string keys are counted)

View source on GitHub