After an AJAX request, sometimes my application may return an empty object, like:
var a = {};
How can I check whether that’s the case?
After an AJAX request, sometimes my application may return an empty object, like:
var a = {};
How can I check whether that’s the case?
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
}