Last active
April 22, 2021 14:13
-
-
Save bhaireshm/f3e08002cc67f42f5e77eb7ce606c09b to your computer and use it in GitHub Desktop.
To check whether the value of any variable is empty.
This file contains 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
/** | |
* @param data - any datatype value. | |
*/ | |
function isEmpty(data) { | |
if (typeof data == "number" || typeof data == "boolean") return false; | |
if (typeof data == "undefined" || data === null) return true; | |
if (typeof data.length != "undefined") return data.length == 0; | |
let count = 0; | |
for (let i in data) if (data.hasOwnProperty(i)) count++; | |
return count == 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment