Created
July 16, 2018 10:21
-
-
Save fyulistian/4e490a33cfc4b98b0db44968a788a5e4 to your computer and use it in GitHub Desktop.
Checking empty object, empty string, undefined by jQuery
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
// function for check empty by data type | |
var is_empty = function(data) { | |
// data type object | |
if (typeof(data) === 'object') { | |
// check empty for data object | |
if (JSON.stringify(data) === '{}' || JSON.stringify(data) === '[]'){ | |
return true; | |
} else if(!data) { | |
return true; | |
} | |
return false; | |
// data type string | |
} else if (typeof(data) === 'string') { | |
// check empty for data string | |
if (!data.trim() || data == "" || data == null){ | |
return true; | |
} | |
return false; | |
// data type undefined | |
} else if (typeof(data) === 'undefined'){ | |
return true; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment