Friday, February 27

How to find if an object is empty in javascript?

I had to find out if an JSON object returned from a web server was empty? Stackoverflow had this documented very clearly. I just wanted note it down here for reference.

var obj = {};
/* Check if an object is empty, you could stringify it and find if it equals to empty set i.e {}*/
if(JSON.stringify(obj) == "{}"){
    console.log("object is empty");
    console.log("object is not empty");

Be the first one to Comment!!!

Post a Comment