Last active
May 29, 2019 15:50
-
-
Save celsobessa/89c91350690f5875c809b1a09366681e to your computer and use it in GitHub Desktop.
isEmpty, a javascript helper for checking if objects are empty.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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