Created
November 8, 2016 06:41
-
-
Save kaveet/ed2413b9cb59c00a6c6273a0ad044e94 to your computer and use it in GitHub Desktop.
Javascript Comprehensive isEmpty Function for Objects
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
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