Created
November 14, 2015 15:14
-
-
Save hernan/755a5bc201db3d687a1e to your computer and use it in GitHub Desktop.
Check for empty object
This file contains hidden or 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
// http://stackoverflow.com/questions/679915/how-do-i-test-for-an-empty-javascript-object | |
//ecma 5+ | |
Object.keys({}).length; // 0 | |
// pre ecma 5 | |
function isEmpty(obj) { | |
for(var prop in obj) { | |
if(obj.hasOwnProperty(prop)) | |
return false; | |
} | |
return true; | |
} | |
jQuery.isEmptyObject({}); // true | |
_.isEmpty({}); // true |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment