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;
}
🌐
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');
}

🌐
SamanthaMing
samanthaming.com › tidbits › 94-how-to-check-if-object-is-empty
How to Check if Object is Empty in JavaScript | SamanthaMing.com
const empty = {}; /* ------------------------- Plain JS for Newer Browser ----------------------------*/ Object.keys(empty).length === 0 && empty.constructor === Object // true /* ------------------------- Lodash for Older Browser ----------------------------*/ _.isEmpty(empty) // true ... A. Empty Object Check in Newer Browsers ... B. Empty Object Check in Older Browsers ... Vanilla JavaScript is not a new framework or library.
🌐
Fjolt
fjolt.com › article › javascript-check-if-object-empty
How to Check if Object is Empty in JavaScript
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:
🌐
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 - In JavaScript, there are various ways you can check if an object is empty. In this article, you will learn the various ways you can do this, the options that can be attached, and why. Note: An object is considered empty when it has no key-value pair.
🌐
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() ...
🌐
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
If you don’t do this check, you’ll ... constructor, such as new Date() or new RegExp(): ... function isEmpty(value) { return value && Object.keys(value).length === 0; } console.log(new Date()); // Date Tue Nov 29 2022 18:18:10 ...
🌐
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 ...
Find elsewhere
🌐
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 - The Object.keys() method returns an array of a given object's own enumerable property names. By checking the length of this array, we can determine if the object is empty or not.
🌐
Flexiple
flexiple.com › javascript › check-if-object-is-empty
How to Check if an Object is Empty in JavaScript – JS Java isEmpty Equivalent - Flexiple
The Object.keys(object) retrieves the keys of object as an array, and checking length === 0 effectively confirms whether there are no properties, thereby indicating emptiness. This approach provides a straightforward and reliable means to check ...
🌐
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.
🌐
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
🌐
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.
🌐
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.
🌐
W3docs
w3docs.com › javascript
How to Check if JavaScript Object is Empty
The length property is used to check the number of keys. If it returns 0 keys, then the object is empty. ... //javascript empty object let obj = {}; function isEmpty(object) { return Object.keys(object).length === 0; } let emptyObj = isEmpty(obj); ...
🌐
Tutorial Republic
tutorialrepublic.com › faq › how-to-test-for-an-empty-object-in-javascript.php
How to Test For an Empty Object in JavaScript
You can simply use the Object.keys() method along with the typeof operator to test for an empty JavaScript object (contains no enumerable properties). Also, since null == undefined is true, obj != null will catch both null and undefined values.
🌐
CoreUI
coreui.io › answers › how-to-check-if-an-object-is-empty-in-javascript
How to check if an object is empty in JavaScript · CoreUI
October 23, 2025 - Use Object.keys() to check if an object has any enumerable properties. ... Here Object.keys(obj) returns an array of all enumerable property names from the object. If the array length equals 0, the object has no properties and is considered empty.
🌐
Leapcell
leapcell.io › blog › how-to-check-if-an-object-is-empty-in-javascript
How to Check if an Object Is Empty in JavaScript | Leapcell
July 25, 2025 - Be careful to check that the value is actually an object and not null, which is also technically an object in JavaScript: function isEmpty(obj) { return obj && typeof obj === "object" && Object.keys(obj).length === 0; } The most reliable and ...
🌐
DEV Community
dev.to › alesm0101 › how-to-check-if-an-object-is-empty-in-javascript-36bj
How to Check if an Object is Empty in JavaScript - DEV Community
November 10, 2023 - const users = {'1': {name: 'alex'}} const currentUser = {} const isEmptyUser = Object.keys(currentUser).length === 0 const isEmptyList = Object.keys(users).length === 0 // or // const isEmptyList = !Object.keys(users).length ... test('should be empty object', () => { expect(isEmptyUser).toBeTruthy() }) test('should not be empty object', () => { expect(isEmptyList).toBeFalsy() })