Created
November 16, 2018 10:05
-
-
Save colorwebdesigner/07f33bc1744f3a7dd5bfb13ea06e8791 to your computer and use it in GitHub Desktop.
Check JS object is emty or not
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
/** | |
* [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