_.isEmpty(obj, true)

var obj = {
  'firstName': undefined
, 'lastName' : undefined
};

console.log(_.isEmpty(obj)); // false
console.log(_.isEmpty({})); // true
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.4/lodash.js"></script>
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Please, see http://www.ericfeminella.com/blog/2012/08/18/determining-if-an-object-is-empty-with-underscore-lo-dash/

Answer from Armen Zakaryan on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › lodash-_-isempty-method
Lodash _.isEmpty() Method - GeeksforGeeks
Lodash _.isEmpty() method checks if the value is an empty object, collection, map, or set. Objects are considered empty if they have no own enumerable string keyed properties. Collections are considered empty if they have a 0 length.
Published   January 9, 2025
🌐
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 - Lodash’s isEmpty method verifies if objects, arrays, maps, or sets are empty, offering a comprehensive check.
People also ask

Why should I use Lodash's isEmpty method in my React project?
Lodash’s isEmpty method is reliable across different types and browsers, and it simplifies code readability.
🌐
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
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
🌐
Medium
medium.com › @trmaphi › lodash-isempty-value-you-might-be-using-it-the-wrong-way-d83210d7decf
Lodash _.isEmpty(value), you might be using it the wrong way. | by Truong Ma Phi | Medium
July 28, 2019 - Upon my discovery of the JavaScript world, I found the heavy use of lodash as my number one library to have a quick, reliable and performance-proven utility belt — my sweet Batman belt. My most common use cases are safely getting nested properties with _.get() and checking empty value with _.isEmpty(). So, _.isEmpty(value) Is this too obvious it checks the value is empty or not? But, my assumption is wrong, it doesn’t work to all types, so according to the documentation · Checks if value is an empty object, collection, map, or set.
🌐
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.
🌐
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');
}

🌐
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.
Find elsewhere
🌐
Lodash
lodash.info › doc › isEmpty
isEmpty - Lodash documentation
Array-like values such as arguments objects, arrays, buffers, strings, or jQuery-like collections are considered empty if they have a length of 0. Similarly, maps and sets are considered empty if they have a size of 0. _.isEmpty(null); // => ...
🌐
Dustin John Pfister
dustinpfister.github.io › 2019 › 09 › 01 › lodash_isempty
The lodash is empty object method for finding out if an object is empty or not | Dustin John Pfister at github pages
November 23, 2020 - In lodash there is the _.isEmpty method than can be used to find if a collection object is empty or not. This is not to be confused with other possible values that might be considered empty such as null, a false boolean value and so forth.
🌐
TutorialsPoint
tutorialspoint.com › lodash › lodash_isempty.htm
Lodash - isEmpty method
Checks if value is an empty object, collection, map, or set.
🌐
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
July 22, 2024 - In this article you will learn five different ways to check if an object is empty in JavaScript. Let’s jump right in. Use Object.keys · Loop Over Object Properties With for…in · Use JSON.stringify · Use jQuery · Use Underscore and Lodash Libraries · Object.keys will return an array, which contains the property names of the object.
Top answer
1 of 16
7554

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
1500

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;
}
🌐
Codingem
codingem.com › home › 5 ways to test if javascript object is empty
5 Ways to Test If JavaScript Object is Empty
July 10, 2025 - With lodash, you can manipulate and iterate over arrays, objects, and strings, as well as functions for creating composite functions and working with asynchronous code. To check if an object is empty using lodash, you can use the _.isEmpty() method.
🌐
GitHub
github.com › lodash › lodash › issues › 5690
The isEmpty method is not very rigorous in judging empty objects. · Issue #5690 · lodash/lodash
June 26, 2023 - The isEmpty method is not very rigorous in judging empty objects. const obj = { [Symbol('a')]: 1 } when I call _.isEmpty(obj), it return true; Have you considered using Reflect.ownKeys() to solve this problem?
Published   Aug 18, 2023
🌐
Morioh
morioh.com › p › 9dcb09453ac9
How to check for empty object in Javascript for Beginners
In this tutorial, you’ll be going to learn how to check if object is empty in javascript. As we do not have any isEmpty() kind of functionality or method in javascript. For that, we need to create a utility helper function or using a library.
🌐
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 - It returns True if object is empty and false otherwise. ... const _ = require("lodash"); let obj = {}; if (_.isEmpty(obj) === true) { console.log("Empty Object") } else console.log("Not Empty Object")