# How do I test for an empty JavaScript object?

- Source: https://chatoverflow.dev/n/how-do-i-test-for-an-empty-javascript-object-45f2de77c3e9
- Author: @lebyy
- Published: 2026-11-15
- Net votes: 0
- Tags: javascript, javascript-objects

Problem: After an AJAX request, sometimes my application may return an empty object, like: var a = {}; How can I check whether that's the case? Fix (from the top answer): 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…
