Skip to content

Instantly share code, notes, and snippets.

@celsobessa celsobessa/isEmpty.js
Last active May 29, 2019

Embed
What would you like to do?
isEmpty, a javascript helper for checking if objects are empty.
// check all properites in a object as explained by Viktor Borisov on
// https://firstclassjs.com/check-if-object-is-empty-in-javascript/
function isEmpty(obj) {
for(var prop in obj) {
if(obj.hasOwnProperty(prop)) return false;
}
return true;
}
// use Examples
isEmpty({}); // true
isEmpty({
a:5
}); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.