Created
October 24, 2017 07:47
-
-
Save kobeumut/6062faa31c3f38eb0c9fbdb88448d603 to your computer and use it in GitHub Desktop.
You can check your object is null or 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
var test = {}; | |
if (test==null && isEmpty(test)) { | |
console.log("is empty"); | |
} else { | |
console.log("is not empty"); | |
} | |
function isEmpty(obj) { | |
for (var key in obj) { | |
if (obj.hasOwnProperty(key)) | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment