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;
}
🌐
SamanthaMing
samanthaming.com › tidbits › 94-how-to-check-if-object-is-empty
How to Check if Object is Empty in JavaScript | SamanthaMing.com
It's just regular, plain JavaScript without the use of a library like Lodash or jQuery. We can use the built-in Object.keys method to check for an empty object.
Discussions

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
How can I verify if a JavaScript object is empty?
Following an AJAX call, my application might sometimes return an empty object, such as: var a = {}; What are the ways to determine if it's indeed empty? More on community.latenode.com
🌐 community.latenode.com
1
October 2, 2024
I often find myself writing Object.keys(someObject) > 0 to test if an object isn't {} (empty) there must be a more beautiful way.
const isEmpty = obj => Object.keys(obj).length === 0; ​ isEmpty({}); // true More on reddit.com
🌐 r/javascript
48
25
September 4, 2018
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
People also ask

Are there any performance considerations when using JSON.stringify() to check if an object is empty?
Yes, `JSON.stringify()` can be slower for large objects due to the string conversion process.
🌐
dhiwise.com
dhiwise.com › post › react-check-if-object-is-empty-a-simple-guide-for-developers
React Check if Object is Empty: A Simple Guide
What is the fastest way to check if an object is empty in React?
The fastest way is to use `Object.keys()`, which checks the object’s properties efficiently.
🌐
dhiwise.com
dhiwise.com › post › react-check-if-object-is-empty-a-simple-guide-for-developers
React Check if Object is Empty: A Simple Guide
Can JSON.stringify() handle circular references when checking for empty objects?
No, `JSON.stringify()` can’t handle circular references and will throw an error if it encounters them.
🌐
dhiwise.com
dhiwise.com › post › react-check-if-object-is-empty-a-simple-guide-for-developers
React Check if Object is Empty: A Simple Guide
🌐
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.
🌐
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.
🌐
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 - We can use Object.entries() similar to how we used methods Object.getOwnPropertNames() and Object.values() to evaluate whether an object is empty. Take a look at the example mentioned below.
🌐
Codedamn
codedamn.com › news › javascript
How to check if an object is empty in JavaScript?
November 18, 2022 - If one of the condition become true we will get our expected result. So hence can find if the object is empty or not using the JSON.stringify() method. In This article, we learn about what an object in JavaScript is.
Find elsewhere
🌐
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.
🌐
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.
🌐
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.
🌐
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 - If the property names JavaScript Array Length of the object is equal to 0, we can confirm the object is empty. Let’s see how to check if a JavaScript object is empty using Object.keys() with an example:
🌐
Fjolt
fjolt.com › article › javascript-check-if-object-empty
How to Check if Object is Empty in JavaScript
February 4, 2023 - ... The easiest (and best) way to do this, is to use Object.keys(). This method turns all the keys in an object to an array, which we can then test the length of: let myObject = {} console.log(Object.keys(myObject).length) // Returns 0! But wait…
🌐
Oprea
oprea.rocks › blog › is-javascript-object-empty.html
Adrian OPREA | Remote Full Stack Software Engineer | How to check if a JavaScript object is empty
January 18, 2019 - try { const attr = await this.contract.methods.attributes(index) .call(this.defaultConfig); const identifierText = Web3.utils.hexToUtf8(attr); return identifierText; } catch (attributeNotFoundException) { logger.info(`No attribute available at position: ${index}`); // THIS is the solution if (Object.keys(attributeNotFoundException).length > 0) { logger.error( `Error retrieving attribute at position ${index} from blockchain: %o`, attributeNotFoundException ); } return null; } Also went on Google and StackOverflow to look for solutions — I usually believe my solutions to be bulletproof, but this time I decided to check 😂. Most common solution is listed below.
🌐
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 - Use Object.keys(obj).length === 0 as the most reliable way to check for emptiness. Always validate that the input is a non-null object before checking. Avoid using JSON.stringify() due to performance and reliability concerns.
🌐
Flexiple
flexiple.com › javascript › check-if-object-is-empty
How to Check if an Object is Empty in JavaScript – JS Java isEmpty Equivalent - Flexiple
May 8, 2024 - 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 ...
🌐
jQuery
api.jquery.com › jQuery.isEmptyObject
jQuery.isEmptyObject() | jQuery API Documentation
To determine if an object is a plain JavaScript object, use $.isPlainObject() Check an object to see if it's 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 - 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. JavaScript ·
🌐
Latenode
community.latenode.com › other questions › javascript
How can I verify if a JavaScript object is empty? - JavaScript - Latenode Official Community
October 2, 2024 - Following an AJAX call, my application might sometimes return an empty object, such as: var a = {}; What are the ways to determine if it's indeed empty?
🌐
GeeksforGeeks
geeksforgeeks.org › typescript › check-if-an-object-is-empty-in-typescript
Check if an Object is Empty in TypeScript - GeeksforGeeks
July 23, 2025 - If no properties are found, the function returns true, indicating that the object is empty. ... Example: The below example uses for...in Loop to check if an Object is empty in TypeScript.
🌐
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.