Created
May 14, 2020 09:26
-
-
Save lucascheung/43a683b2c28d2b167378cf79d1441f4b to your computer and use it in GitHub Desktop.
Check if a JavaScript object is empty
This file contains hidden or 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 isEmpty(obj) { | |
for(var prop in obj) { | |
if(obj.hasOwnProperty(prop)) { | |
return false; | |
} | |
} | |
return JSON.stringify(obj) === JSON.stringify({}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment