Skip to content

Instantly share code, notes, and snippets.

@hernan
Created November 14, 2015 15:14
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 hernan/755a5bc201db3d687a1e to your computer and use it in GitHub Desktop.
Save hernan/755a5bc201db3d687a1e to your computer and use it in GitHub Desktop.
Check for empty object
// 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