Use Object.keys(obj).length to check if it is empty.

Output : 3

Source: Object.keys()

Answer from DeepSea on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › check-if-an-object-is-empty-in-typescript
Check if an Object is Empty in TypeScript - GeeksforGeeks
July 23, 2025 - In this approach, we are using the Object.keys() function in TypeScript to check if an object is empty.
Discussions

How do I test for an empty JavaScript object? - Stack Overflow
After an AJAX request, sometimes my application may return an empty object, like: var a = {}; How can I check whether that's the case? More on stackoverflow.com
🌐 stackoverflow.com
Utility type to decide if a type is empty or inhabited
I wonder if this could be useful for writing type-level unit tests? More on reddit.com
🌐 r/typescript
7
1
June 13, 2024
What is the best method to check if a variable is not null or empty?
It depends what you mean by empty, or how strict you want to be. These values will coerce to false: undefined null '' (empty string) 0 NaN Everything else coerces to true. So, if you are OK with rejecting all of those values, you can do: if(PostCodeInformation) { } If you want to make sure that PostCodeInformation is really an object value (and not a number or boolean, etc): if(typeof PostCodeInformation === 'object' && PostCodeInformation !== null) { } You have to do the null-check there, because in JavaScript typeof null returns 'object'. So dumb. If you want to make sure that PostCodeInformation has some property that you really need: if(PostCodeInformation && PostCodeInformation.myCoolProperty) { } Etc, etc More on reddit.com
🌐 r/javascript
18
3
August 2, 2015
why there isn't a method to check an object is empty or not?
Object.keys().length will give you the number of keys in an object. More on reddit.com
🌐 r/learnjavascript
11
0
March 13, 2022
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › how-to-check-if-an-object-is-empty-in-typescript
How to Check if an Object is Empty in TypeScript ? - GeeksforGeeks
July 23, 2025 - Converting the object into a JSON string allows for easy checking if it's empty by verifying the length of the resulting string. Example: This example shows the use of the above-explained approach.
🌐
Bobby Hadz
bobbyhadz.com › blog › typescript-check-if-object-is-empty
Check if an Object is Empty in TypeScript | bobbyhadz
The lodash.isempty method checks if the supplied value is an empty object, collection, Map or Set.
Top answer
1 of 16
7557

You can use a for…in loop with an Object.hasOwn (ECMA 2022+) test to check whether an object has any own properties:

function isEmpty(obj) {
  for (const prop in obj) {
    if (Object.hasOwn(obj, prop)) {
      return false;
    }
  }

  return true;
}

If you also need to distinguish {}-like empty objects from other objects with no own properties (e.g. Dates), you can do various (and unfortunately need-specific) type checks:

function isEmptyObject(value) {
  if (value == null) {
    // null or undefined
    return false;
  }

  if (typeof value !== 'object') {
    // boolean, number, string, function, etc.
    return false;
  }

  const proto = Object.getPrototypeOf(value);

  // consider `Object.create(null)`, commonly used as a safe map
  // before `Map` support, an empty object as well as `{}`
  if (proto !== null && proto !== Object.prototype) {
    return false;
  }

  return isEmpty(value);
}

Note that comparing against Object.prototype like in this example will fail to recognize cross-realm objects.

Do not use Object.keys(obj).length. It is O(N) complexity because it creates an array containing all the property names only to get the length of that array. Iterating over the object accomplishes the same goal but is O(1).

For compatibility with JavaScript engines that don’t support ES 2022+, const can be replaced with var and Object.hasOwn with Object.prototype.hasOwnProperty.call:

function isEmpty(obj) {
  for (var prop in obj) {
    if (Object.prototype.hasOwnProperty.call(obj, prop)) {
      return false;
    }
  }

  return true
}

Many popular libraries also provide functions to check for empty objects:

jQuery:

jQuery.isEmptyObject({}); // true

lodash:

_.isEmpty({}); // true

Underscore:

_.isEmpty({}); // true

Hoek:

Hoek.deepEqual({}, {}); // true

ExtJS:

Ext.Object.isEmpty({}); // true

AngularJS (version 1):

angular.equals({}, {}); // true

Ramda:

R.isEmpty({}); // true
2 of 16
1504

If ECMAScript 5 support is available, you can use Object.keys():

function isEmpty(obj) {
    return Object.keys(obj).length === 0;
}

For ES3 and older, there's no easy way to do this. You'll have to loop over the properties explicitly:

function isEmpty(obj) {
    for(var prop in obj) {
        if(obj.hasOwnProperty(prop))
            return false;
    }

    return true;
}
🌐
Reddit
reddit.com › r/typescript › utility type to decide if a type is empty or inhabited
r/typescript on Reddit: Utility type to decide if a type is empty or inhabited
June 13, 2024 -

I have been having fun trying to build a type to check if a TS type is empty or inhabited. Initially I thought that I could just check if the type extends never but it turns out that empty object types like {foo: never} don't extend never and similarly, empty tuple types like [string, never] also don't extend never.

So I built a type that determines if a type is empty by recusively checking the properties and handling the edge cases. I learned a lot about the subtype relations and about how conditional types work. Figuring out the distribution over unions was particularly tricky.

I'm sure I've missed some edge cases, please let me know if the comments if you find it useful/interesting or if there is something that doesn't work as expected.

Github

TS Playground

Find elsewhere
🌐
Decipher
decipher.dev › isempty
isEmpty | 30 Seconds of Typescript - Decipher.dev
Returns true if the a value is an empty object, collection, has no enumerable properties or is any type that is not considered a collection. Check if the provided value is null or if its length is equal to 0. ... const isEmpty = (val: any) => ...
🌐
SPGuides
spguides.com › typescript-check-if-object-is-empty
How to Check If Object Is Empty in TypeScript?
July 20, 2025 - Type It Right: For strict typing, Record<string, never> enforces empty objects in TypeScript definitions. Handle Edge Cases: Always check input types to prevent runtime errors from null, undefined, or arrays. Utility Libraries: Only use libraries like Lodash if your project already includes them or you need extra utility.
🌐
Total TypeScript
totaltypescript.com › the-empty-object-type-in-typescript
The Empty Object Type in TypeScript | Total TypeScript
April 2, 2024 - The empty object type in TypeScript doesn't really behave as you expect. It doesn't represent "any object". Instead, it represents any value that isn't null or undefined. Try experimenting with it in the playground below: Here, we are basically typing example1 as an empty object, yet we can pass a string to it. We can pass a number to it. We can pass a boolean to it and any object to it.
🌐
Fjolt
fjolt.com › article › javascript-check-if-object-empty
How to Check if Object is Empty in JavaScript
February 4, 2023 - let empty = {} let isObjEmpty = (obj) => { return Object.keys(obj).length === 0 && obj.constructor === Object } console.log(isObjEmpty(empty)); // Returns true, Object is empty! This will not work if some keys are non-enumerable, though.
🌐
DEV Community
dev.to › smpnjn › how-to-check-if-object-is-empty-in-javascript-5afl
How to Check if Object is Empty in JavaScript - DEV Community
February 5, 2023 - Fortunately, we can use Object.getOwnPropertyNames to get all non-enumerable and enumerable keys on an object. Therefore, to check if an object is empty and check for both enumerable and non-enumerable keys, we only have to change Object.keys to Object.getOwnPropertyNames:
🌐
Medium
mingyang-li.medium.com › easiest-way-to-check-for-empty-objects-in-javascript-ab11a004ed57
Easiest Way To Check For Empty Objects In JavaScript | by Mingyang Li | Medium
February 20, 2024 - The safest way to check if an object is empty in JavaScript is to convert it into a string and check if it equals to a plan "{}" string — if you’re not using a library. Hope this helps.
🌐
DhiWise
dhiwise.com › blog › design-converter › typescript-empty-object-guide-best-practices
Understanding the TypeScript Empty Object
March 3, 2025 - The way TypeScript handles empty objects depends on type rules, object literals, and assignable values.
🌐
Built In
builtin.com › software-engineering-perspectives › javascript-check-if-object-is-empty
How to Check If an Object Is Empty in JavaScript | Built In
Tutorials for Software Developers on Built InCreate React App and TypeScript — A Quick How-To · If we stringify the object and the result is simply an opening and closing bracket, we know the object is empty. function isEmptyObject(obj){ ...
🌐
freeCodeCamp
freecodecamp.org › news › check-if-an-object-is-empty-in-javascript
How to Check if an Object is Empty in JavaScript – JS Java isEmpty Equivalent
November 7, 2024 - For example, if you want to check if an object is empty, you only need to use the "isEmpty" method.
🌐
xjavascript
xjavascript.com › blog › typescript-check-if-object-is-empty
TypeScript: Checking if an Object is Empty — xjavascript.com
function isObjectEmptyUsingForIn(obj: object): boolean { for (const key in obj) { if (obj.hasOwnProperty(key)) { return false; } } return true; } // Example usage const emptyObj3 = {}; const nonEmptyObj3 = { item: 'info' }; console.log(isObjectEmptyUsingForIn(emptyObj3)); // true console.log(isObjectEmptyUsingForIn(nonEmptyObj3)); // false · Performance Consideration: When dealing with large objects, Object.keys() is generally faster than using a for...in loop. JSON.stringify() can be slow and has limitations, especially if the object contains functions or symbols. Type Safety: Always use proper TypeScript types when working with objects.
🌐
Sentry
sentry.io › sentry answers › javascript › how do i test for an empty javascript object?
How do I Test for an Empty JavaScript Object? | Sentry
December 15, 2022 - This method was used as an alternative to using Object.keys before it was added to JavaScript in the 2011 ECMAScript 5 specification and is widely supported by browsers. You can use JSON.stringify() to convert the value to a JSON string to check if the value is an empty object.
🌐
xjavascript
xjavascript.com › blog › check-if-specific-object-is-empty-in-typescript
TypeScript: How to Check if an Object is Empty (Fixing 'if (object)' Not Working) — xjavascript.com
In JavaScript and TypeScript, objects—even empty ones—are **truthy**, meaning `if ({})` will always evaluate to `true`. This can lead to frustrating bugs if you’re not aware of how object truthiness works.