Skip to content

Instantly share code, notes, and snippets.

@kaveet
Created November 8, 2016 06:41
Show Gist options
  • Save kaveet/ed2413b9cb59c00a6c6273a0ad044e94 to your computer and use it in GitHub Desktop.
Save kaveet/ed2413b9cb59c00a6c6273a0ad044e94 to your computer and use it in GitHub Desktop.
Javascript Comprehensive isEmpty Function for Objects
var hasOwnProperty = Object.prototype.hasOwnProperty;
function isEmpty(obj) {
if (obj == null) return true;
if (obj.length > 0) return false;
if (obj.length === 0) return true;
if (typeof obj !== "object") return true;
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment