CyrefJS
CCyrefJS
فا
Back to documentation
Object/Since 1.38.0

isEmptyObject

Checks whether an object has no own enumerable string-keyed properties.

isEmptyObject(object):boolean

How 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

objectobjectrequired

The object to check.

Returns

boolean

true if the object has no own enumerable string-keyed properties; otherwise, false.

Examples

01

Empty object

TypeScript
isEmptyObject({});
// true
02

Object with properties

TypeScript
isEmptyObject({
  name: "Amir",
});
// false
03

Undefined values still count

TypeScript
isEmptyObject({
  value: undefined,
});
// false
04

Null values still count

TypeScript
isEmptyObject({
  value: null,
});
// false
05

Non-enumerable properties

TypeScript
const object = {};

Object.defineProperty(object, "hidden", {
  value: 123,
  enumerable: false,
});

isEmptyObject(object);
// true
06

Symbol properties

TypeScript
const id = Symbol("id");

const object = {
  [id]: 123,
};

isEmptyObject(object);
// true
07

Inherited properties

TypeScript
const parent = {
  name: "Amir",
};

const object = Object.create(parent);

isEmptyObject(object);
// true
Built with@cyref/js·Official documentation