Object/Since
1.38.0isEmptyObject
Checks whether an object has no own enumerable string-keyed properties.
isEmptyObject(object):booleanHow it works
The function uses Object.keys and checks whether the resulting array contains zero keys.
Included properties
Only own enumerable string-keyed properties are considered. Symbol properties, non-enumerable properties, and inherited properties are ignored.
Parameters
objectobjectrequiredThe object to check.
Returns
booleantrue if the object has no own enumerable string-keyed properties; otherwise, false.
Examples
01
Empty object
TypeScript
isEmptyObject({});
// true02
Object with properties
TypeScript
isEmptyObject({
name: "Amir",
});
// false03
Undefined values still count
TypeScript
isEmptyObject({
value: undefined,
});
// false04
Null values still count
TypeScript
isEmptyObject({
value: null,
});
// false05
Non-enumerable properties
TypeScript
const object = {};
Object.defineProperty(object, "hidden", {
value: 123,
enumerable: false,
});
isEmptyObject(object);
// true06
Symbol properties
TypeScript
const id = Symbol("id");
const object = {
[id]: 123,
};
isEmptyObject(object);
// true07
Inherited properties
TypeScript
const parent = {
name: "Amir",
};
const object = Object.create(parent);
isEmptyObject(object);
// trueBuilt with@cyref/js·Official documentation