I have an ajax call that creates html elements based on a loop. Some of the data in my call is empty and will display as undefined, I am trying to find a way to have it display as zero.
success: function(response) {
var results = response.results;
var html = '';
for (var i = 0; i < results.length; i++){
html += '<span class="test">' + results[i].code + '</span>'
}
}
$('#mydiv').html(html);
The above code would display like this.
123
456
undefined
678
undefined
How can i suppress the undefined to print like
123
456
0
678
0