Skip to content

Instantly share code, notes, and snippets.

@celsobessa
Last active May 29, 2019 15:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save celsobessa/89c91350690f5875c809b1a09366681e to your computer and use it in GitHub Desktop.
Save celsobessa/89c91350690f5875c809b1a09366681e to your computer and use it in GitHub Desktop.
isEmpty, a javascript helper for checking if objects are empty.
// check all properites in a object as explained by Viktor Borisov on
// https://firstclassjs.com/check-if-object-is-empty-in-javascript/
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop)) return false;
}
return true;
}
// use Examples
isEmpty({}); // true
isEmpty({
a:5
}); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment