How make website with JavaScript

After an AJAX request, sometimes my application may return an empty object, like:

var a = {};

How can I check whether that’s the case?

1 Like

You can check the length of Object.keys, which returns an array of a given object’s own enumerable property names.

const myObj = {};

if(Object.keys(myObj).length === 0) {
  // It's an empty object
} else {
  // The object isn't empty
}
2 Likes