What is the best solution to undefined
values being returned by database when the column is empty. Is there another way than having
if (!(databasevalue == 'undefined') || !(databasevalue == null)) {
console.log(databasevalue)
} else {
console.log('Value is empty')
}
This is ok if only few values can be empty what if multiple values can be empty DO i check each value if undefined or not then show the result
UPDATE
$.ajax({
type: 'POST',
url: 'php',
dataType: "json",
data: {
id: "id"
},
success: function (data) {
//check which data is undefined or not
},
error: function (data) {
console.log(data);
}
});
Is there are collective checking to see which data from the response is undefined or you need to check each have an if condition to check if the data is empty or not
You need to use &&
operator instead of ||
and undefined
should not be in quotes
if (!(databasevalue == undefined) && !(databasevalue == null)) {
console.log(databasevalue)
} else {
console.log('Value is empty');
}
However simplest solution is you should check for truthy
condition, Following condition is to check databasevalu
has value
if (databasevalu) { //!!databasevalu
console.log(databasevalue)
} else {
console.log('Value is empty');
}
!!
double-negation is used for conversion of condition to boolean
instead of truthy
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments