There are various ways to check if an object is empty in JavaScript.
Method 1: Using JavaScript JSON.stringify
method –
var obj = {};
if(JSON.stringify(obj) === '{}') { //Object is empty
//Code here..
}
Method 2: Looping through object keys –
function isEmpty(obj) {
for(var i in obj) return false;
return true;
}
var obj = {};
isEmpty(obj) //true