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
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;
}
🌐
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 - Lodash is a modern JavaScript utility library that can perform many JavaScript functionalities with very basic syntax. For example, if you want to check if an object is empty, you only need to use the "isEmpty" method.
🌐
Zipy
zipy.ai › blog › how-do-i-test-for-an-empty-javascript-object
how do i test for an empty javascript object
April 12, 2024 - Throughout this article, we'll explore various techniques for checking if an object is empty in JavaScript. We'll cover built-in methods, custom functions, and best practices to ensure efficient and effective object handling.
🌐
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');
}

🌐
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
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.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-check-an-object-is-empty-using-javascript
How to Check an Object is Empty using JavaScript? - GeeksforGeeks
July 11, 2025 - let obj = {}; if (Object.keys(obj).length === 0) { console.log("Empty Object") } else { console.log("Not Empty Object") } ... A function can be created to loop over the object and check if it contains any properties using object.hasOwnProperty() ...
🌐
Bonsaiilabs
bonsaiilabs.com › check-empty-object
How to check if a JavaScript Object is Empty - bonsaiilabs
So always check whether the object is null or undefined before checking if it's empty. Otherwise it may result in runtime errors. Now when we run it next time, it doesn't give any output. That's because users is already null and the message is going to be displayed. If users is a valid object and the number of entries inside the object are zero. Since that is not the case, it didn't displayed any message.
🌐
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 - Easiest Way To Check For Empty Objects In JavaScript What’s so difficult about checking if an object is empty? Isn’t it as simple as doing this — const isEmpty = yourObject === {} ? Well, I …
Find elsewhere
🌐
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
This tutorial shows you how to detect if an object is empty in JavaScript. ... JavaScript provides the Object.keys() method returning the array of keys from the given object. You can leverage this method detecting whether the number of keys is zero which tells you a given object is empty: const ...
🌐
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
We can also check this using Object.values and Object.entries. This is typically the easiest way to determine if an object is empty. ... The for…in statement will loop through the enumerable property of the object.
🌐
SamanthaMing
samanthaming.com › tidbits › 94-how-to-check-if-object-is-empty
How to Check if Object is Empty in JavaScript | SamanthaMing.com
It will return false and not throw a TypeError. isObjectEmpty(null); // false isObjectEmpty(undefined); // false · There are tons of external libraries you can use to check for empty objects. And most of them have great support for older browsers 👍 ... The answer is it depends! I'm a huge fan of going vanilla whenever possible as I don't like the overhead of an external library. Plus for smaller apps, I'm too lazy to set up the external library 😂. But if your app already has an external library installed, then go ahead and use it.
🌐
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 - When the object is not null or undefined, we check if the object is empty using the Object.keys() method. If the object is empty, we print a message to the console “The object is empty.” · If the JavaScript object is not empty, we print ...
🌐
Envato Tuts+
code.tutsplus.com › home › coding fundamentals
How to Check if an Object Is Empty in JavaScript | Envato Tuts+
April 29, 2022 - It will work with null and undefined values—returning false because these are not objects. For special objects like Date and RegExp, it will return true because they don't have any special keys defined. It will also return true for an empty array and false for a non-empty array. In this section, we’ll discuss a solution which would work even with older browsers. This was used frequently until the JavaScript ES5 era, when there were no built-in methods available to check if an object is empty.
🌐
Stack Abuse
stackabuse.com › javascript-check-if-an-object-is-empty
JavaScript: Check if an Object is Empty
April 5, 2023 - In this tutorial - learn how to check if an object is empty in JavaScript with Vanilla JS, jQuery, Lodash, Underscore, Ramda and Hoek, with practical code examples!
🌐
Flexiple
flexiple.com › javascript › check-if-object-is-empty
How to Check if an Object is Empty in JavaScript – JS Java isEmpty Equivalent - Flexiple
If an object is non-empty, the loop sets hasProperty to true at the discovery of the first property and exits the loop. If the object is empty, the loop never initiates, and isEmpty confirms the absence of properties by returning true.
🌐
Scaler
scaler.com › home › topics › how to check if an object is empty in javascript?
How to Check if an Object is Empty in JavaScript - Scaler Topics
January 6, 2024 - It provides flexibility to be used as a simple component framework and as a full framework to build a single-page application. ExtJS provides a method isEmpty() to check if an object is empty or not.
🌐
Coderwall
coderwall.com › p › _g3x9q › how-to-check-if-javascript-object-is-empty
How to check if JavaScript Object is empty (Example)
July 27, 2025 - Then you can easily check if the object is empty like so. var myObj = { myKey: "Some Value" } if(myObj.isEmpty()) { // Object is empty } else { // Object is NOT empty (would return false in this example) }
🌐
DhiWise
dhiwise.com › post › react-check-if-object-is-empty-a-simple-guide-for-developers
React Check if Object is Empty: A Simple Guide
November 6, 2024 - Object.keys() offers a straightforward way to check if an object is empty in JavaScript, making it particularly useful in React applications.
🌐
Fjolt
fjolt.com › article › javascript-check-if-object-empty
How to Check if Object is Empty in JavaScript
Therefore, we can check if an object is empty if its constructor is an Object, and it has an Object.keys() value of 0: let empty = {} let isObjEmpty = (obj) => { return Object.keys(obj).length === 0 && obj.constructor === Object } ...
🌐
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 - Therefore, we can check if an object is empty if its constructor is an Object, and it has an Object.keys() value of 0: let empty = {} let isObjEmpty = (obj) => { return Object.keys(obj).length === 0 && obj.constructor === Object } ...