Created
May 16, 2018 13:45
-
-
Save hiulit/805821aede4b625b3c114536b557ca5d to your computer and use it in GitHub Desktop.
Function to check if a JavaScript Object is 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
function isObjectEmpty(obj) { | |
for(var key in obj) { | |
if(obj.hasOwnProperty(key)) | |
return false | |
} | |
return true | |
} | |
var myObj = {}; // Empty Object | |
if(isObjectEmpty(myObj)) { | |
// Object is empty (Would return true in this example) | |
} else { | |
// Object is NOT empty | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Credits: https://coderwall.com/p/_g3x9q/how-to-check-if-javascript-object-is-empty