Skip to content

Instantly share code, notes, and snippets.

@lucascheung
Created May 14, 2020 09:26
Show Gist options
  • Save lucascheung/43a683b2c28d2b167378cf79d1441f4b to your computer and use it in GitHub Desktop.
Save lucascheung/43a683b2c28d2b167378cf79d1441f4b to your computer and use it in GitHub Desktop.
Check if a JavaScript object is empty
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop)) {
return false;
}
}
return JSON.stringify(obj) === JSON.stringify({});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment