4
I am trying to create a function that checks if you have something blank, empty, Undefined, null etc..
But my difficulty is that I don’t know all the ways a string is "blank"
I created this function
function empty() {
var args = [].slice.call(arguments);
args.forEach(function(argument) {
if(!argument || 0 === argument.length || !argument || /^\s*$/.test(argument) || argument.length === 0 || !argument.trim()) {
return false;
}
});
}
the intention is to return false
so that I can simply check if among my variables there are any blank ones in this way if(!empty(var1, var2...)) {
But there are several ways, as I said, for example in my doubts:
If it is an array, how to know if it is empty?
If it is a JSON how to know if it is empty?
If it’s just numbers, you can tell if it’s empty?
are so many ways you have to check that I get lost..
When I say empty I mean Undefined, null, filled only with empty spaces etc..
Should the zero number validate true or false? What types of values do you have?
– Sergio
@Sergio the number itself must refer to false, if it is in a true string..
– Elaine