I have a stream of JSON coming back and am building a table dynamically with it’s values. I’m having an issue where values which are “NULL” in the database are actually being returned in the JSON with a NULL value.
I’d rather my output to my users not display NULL.
Is there a more efficient way of handling this other than how I am doing it?
if(data[i][2] != null){
foo = '';
}else{
foo = data[i][2];
}
htmlString += '<td>' + foo+ '</td>';
this is equivalent for
take value of data[i][2] when it has some, else take the second one
The value of data[i][2] will be assigned to cleanData if its not evalated to false, for Eg :false, null, undefined, 0, zero-length string or NaN are evaluated to false. Otherwise ‘my fall back value’ is taken.
So obviously, if your variable need to take up any of these values(like 0) the solution is not perfect.
looks more reliable.