Created
July 3, 2016 04:50
-
-
Save ZhihaoLau/cbe79fa2fcd3b8a8f3c4a43973b597ce to your computer and use it in GitHub Desktop.
Check if 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
// pre es5 | |
function isEmpty(myObject) { | |
for (var key in myObject) { | |
if (myObject.hasOwnProperty(key)) { | |
return false | |
} | |
} | |
return true | |
} | |
// es5 | |
function isEmpty(myObject) { | |
return Object.keys(myObject).length === 0 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment