Skip to content

Instantly share code, notes, and snippets.

@ZhihaoLau
Created July 3, 2016 04:50
Show Gist options
  • Save ZhihaoLau/cbe79fa2fcd3b8a8f3c4a43973b597ce to your computer and use it in GitHub Desktop.
Save ZhihaoLau/cbe79fa2fcd3b8a8f3c4a43973b597ce to your computer and use it in GitHub Desktop.
Check if object is empty
// 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