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.
๐ŸŒ
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 - const obj5: Record<string, any> = {}; const obj6: Record<string, any> = { fruit: "Apple", quantity: 5 }; function isEmpty(obj: Record<string, any>): boolean { for (const key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { return false; } } return true; } if (isEmpty(obj5)) { console.log('obj5 is empty'); } else { console.log('obj5 is not empty'); } if (isEmpty(obj6)) { console.log('obj6 is empty'); } else { console.log('obj6 is not empty'); } ... Converting the object into a JSON string allows for easy checking if it's empty by verifying the length of the resulting string. Exam
๐ŸŒ
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.
๐ŸŒ
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:
๐ŸŒ
Total TypeScript
totaltypescript.com โ€บ the-empty-object-type-in-typescript
The Empty Object Type in TypeScript | Total TypeScript
April 2, 2024 - Type 'null' is not assignable to type 'Object'.2322Type 'null' is not assignable to type 'Object'. So this behaves in exactly the same way. So you shouldn't be using this Object type either. # If you do want to represent a kind of empty object, then we can use this Record<PropertyKey, never>.
๐ŸŒ
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
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) => ...
๐ŸŒ
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
If the length of the array is 0, then we know that the object is empty. function isEmpty(obj) { return **Object.keys(obj).length === 0**; } We can also check this using Object.values and Object.entries.
๐ŸŒ
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. In this tutorial, I explained how to check if an object is empty in TypeScript using different methods with examples.
๐ŸŒ
DEV Community
dev.to โ€บ onlinemsr โ€บ 7-easy-ways-to-check-if-an-object-is-empty-in-javascript-ddm
7 Easy Ways To Check If An Object Is Empty In JavaScript - DEV Community
July 5, 2023 - An empty object has no properties. An undefined object is not defined. A null object is an object that has no value. Refer the following code to check if an object is empty, undefined, or null:
๐ŸŒ
Reddit
reddit.com โ€บ r/javascript โ€บ i often find myself writing object.keys(someobject) > 0 to test if an object isn't {} (empty) there must be a more beautiful way.
r/javascript on Reddit: I often find myself writing Object.keys(someObject) > 0 to test if an object isn't {} (empty) there must be a more beautiful way.
September 4, 2018 -

Hi everyone,

I very often find myself writing something like

if( Object.keys(someObject).length > 0 ) {

//do some wild stuff

}

To check if a basic object is empty or not i.e. not {} there must be a beautiful way.

I know lodash and jQuery have their solutions, but I don't want to import libraries for a single method, so I'm about to write a function to use across a whole project, but before I do that I want to know I'm not doing something really stupid that ES6/ES7/ES8 can do that I'm just not aware of.

edit solution courtesy of u/vestedfox

Import https://www.npmjs.com/package/lodash.isequal

Total weight added to project after compilation: 355 bytes

Steps to achieve this.

npm i --save lodash.isequal

then somewhere in your code

const isEqual = require('lodash.isequal');

If you're using VueJS and don't want to have to include this in every component and don't want to pollute your global namespace you can do this in app.js

const isEqual = require('lodash.isequal');
Vue.mixin({
  methods: {
    isEqual: isEqual
  }
});

Then in your components you can simply write.

if( this.isEqual(someObject, {})) {
   console.log('This object has properties');
}

๐ŸŒ
Fjolt
fjolt.com โ€บ article โ€บ javascript-check-if-object-empty
How to Check if Object is Empty in JavaScript
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.
Top answer
1 of 16
7555

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

Copyfunction 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:

Copyfunction 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:

Copyfunction 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:

CopyjQuery.isEmptyObject({}); // true

lodash:

Copy_.isEmpty({}); // true

Underscore:

Copy_.isEmpty({}); // true

Hoek:

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

ExtJS:

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

AngularJS (version 1):

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

Ramda:

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

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

Copyfunction 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:

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

    return true;
}
๐ŸŒ
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.
๐ŸŒ
Futurestud.io
futurestud.io โ€บ tutorials โ€บ how-to-check-if-an-object-is-empty-in-javascript-or-node-js
How to Check if an Object is Empty in JavaScript or Node.js
You may also create yourself a helper function accepting the object as a parameter and returning true when empty and false when not: function isEmpty(object) { return Object.keys(object).length === 0 } isEmpty({}) // true isEmpty({ name: 'Marcus' }) // false
๐ŸŒ
DhiWise
dhiwise.com โ€บ blog โ€บ design-converter โ€บ typescript-empty-object-guide-best-practices
Understanding the TypeScript Empty Object
March 3, 2025 - An empty object in TypeScript is assignable to all object types but is not assignable to primitive types such as string, number, or boolean.