Skip to content

Instantly share code, notes, and snippets.

@hiulit
Created May 16, 2018 13:45
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 hiulit/805821aede4b625b3c114536b557ca5d to your computer and use it in GitHub Desktop.
Save hiulit/805821aede4b625b3c114536b557ca5d to your computer and use it in GitHub Desktop.
Function to check if a JavaScript Object is empty
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
}
@hiulit
Copy link
Author

hiulit commented May 16, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment