Skip to content

Instantly share code, notes, and snippets.

@colorwebdesigner
Created November 16, 2018 10:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colorwebdesigner/07f33bc1744f3a7dd5bfb13ea06e8791 to your computer and use it in GitHub Desktop.
Save colorwebdesigner/07f33bc1744f3a7dd5bfb13ea06e8791 to your computer and use it in GitHub Desktop.
Check JS object is emty or not
/**
* [isEmtyObj]
*
* @param {[object]} obj [description]
* @return {[boolean]} [description]
*/
function isEmptyObj(obj) {
// console.log('Obj cont: ' + obj);
// console.log(`Obj leng: ${obj.length}`);
// console.log(`Obj type: ${typeof(obj)}`);
if (obj == null) return true;
if (obj.length > 0) return false;
if (obj.length === 0) return true;
if (typeof(obj) !== "object") return true;
for (var key in obj) {
if (hasOwnProperty.call(obj, key)) return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment