Check all values with Object.values. It returns an array with the values, which you can check with Array.prototype.every or Array.prototype.some:

const isEmpty = Object.values(object).every(x => x === null || x === '');
const isEmpty = !Object.values(object).some(x => x !== null && x !== '');
Answer from PVermeer on Stack Overflow
🌐
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 - Note: An object is considered empty when it has no key-value pair. In case you are in a rush, here is a basic example: const myEmptyObj = {}; // Works best with new browsers Object.keys(myEmptyObj).length === 0 && myEmptyObj.constructor === ...
🌐
Stack Overflow
stackoverflow.com › questions › 76962710 › how-to-check-specific-object-key-value-is-empty-or-not-in-nested-object-in-javas
How to check specific object key value is empty or not in nested object in JavaScript? - Stack Overflow
Objects are not iterable and you can not loop over them and instead, you should try to convert them to something iterable (like arrays) and then loop over them and you can do this with Object.entries() which will pack key value pairs inside of an object inside an array.
🌐
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 - Checking if an object is empty, undefined, or null is essential in JavaScript programming. We have explored different methods in this article to determine if an object has any properties or not. This helps you to avoid runtime errors when trying to access a property that really not exists in an object. The methods we have covered include Object.keys(), for…in loop, Object.values(), Object.entries(), Object.getOwnPropertyNames(), Reflect.ownKeys(), and Object.getOwnPropertySymbols().
🌐
SamanthaMing
samanthaming.com › tidbits › 94-how-to-check-if-object-is-empty
How to Check if Object is Empty in JavaScript | SamanthaMing.com
So just using the Object.keys, it does return true when the object is empty ✅. But what happens when we create a new object instance using these other constructors. function badEmptyCheck(value) { return Object.keys(value).length === 0; } badEmptyCheck(new String()); // true 😱 badEmptyCheck(new Number()); // true 😱 badEmptyCheck(new Boolean()); // true 😱 badEmptyCheck(new Array()); // true 😱 badEmptyCheck(new RegExp()); // true 😱 badEmptyCheck(new Function()); // true 😱 badEmptyCheck(new Date()); // 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');
}

🌐
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 - 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.
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;
}
🌐
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 ...
Find elsewhere
🌐
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, 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: let empty = {} // Example: Add a non-enumerable property to our object using ...
🌐
W3docs
w3docs.com › javascript
How to Check if JavaScript Object is Empty
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); console.log(emptyObj);
🌐
Stack Overflow
stackoverflow.com › questions › 64534247 › check-if-object-key-is-empty
javascript - Check if object key is empty - Stack Overflow
const params = { name: '', email: '[email protected]', profession: 'Content Writer', age: 29 }; const sp = new URLSearchParams() Object.keys(params).forEach((key) => { if (params[key]) sp.set(key,params[key]) }) console.log(sp.toString())
🌐
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 ...
🌐
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") }
🌐
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 - using hasOwnProperty allows for skipping over "built in" or "metadata" properties, and just evaluate "value" properties. ... If you don't want to copy-paste this all over your different repositories, you can also try this NPM package or this Bit component. They should work just fine and make it useable anywhere you need. ... const isEmpty = function (input) { if (typeof input === 'array') { return input.length === 0; } return !input || Object.keys(input).length === 0; }
🌐
Bonsaiilabs
bonsaiilabs.com › check-empty-object
How to check if a JavaScript Object is Empty - bonsaiilabs
To check for empty objects, JavaScript provides a method on objects called entries. It returns an array of entries an object contains. We can use it by calling object.entries and pass it as an argument users whose key value pairs are to be returned.
🌐
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.
🌐
Scaler
scaler.com › topics › check-if-object-is-empty-javascript
How to Check if an Object is Empty in JavaScript - Scaler Topics
December 8, 2022 - There is no built-in method to determine if an object in JavaScript is empty. In this article we discussed several different methods we can use to determine whether a JavaScript object is empty or not using plain JavaScript or using external libraries. We can use object methods like .keys(), .values(), or .getOwnPropertyNames() to determine whether an object is empty or not.
🌐
TutorialsPoint
tutorialspoint.com › how-to-check-if-an-object-is-empty-using-javascript
How to check if an object is empty using JavaScript?
We can iterate through every key of an object using the for-in loop. Here, we will use the for-in loop and check that if it makes a single iteration for the object, the object contains at least one property and is not empty. Users can follow the syntax below to check whether the object is empty ...
🌐
Stack Abuse
stackabuse.com › javascript-check-if-an-object-is-empty
JavaScript: Check if an Object is Empty
April 5, 2023 - When it comes to small applications that don't require external dependencies - checking whether an object is empty is best done with pure JavaScript. However, if your application already has external libraries such as lodash and underscore - they offer great ways to perform these checks as well. Checking if an object is empty or not is a basic and frequent operation, however, there are several methods for determining whether it's empty or not. Let's start by creating an empty Object with the object literal syntax: ... Object.keys() is a static method that returns an Array when we pass an object to it, which contains the property names (keys) belonging to that object.