How would I make this append only if telephone exists and skip if telephone doesn't exist
for (var i in data.businesses) {
$('body').append( "<p>" + data.businesses[i].telephone + "</p>");
}
How would I make this append only if telephone exists and skip if telephone doesn't exist
for (var i in data.businesses) {
$('body').append( "<p>" + data.businesses[i].telephone + "</p>");
}
Try
$.each(data.businesses, function(index, business){
if(business.telephone){
$('body').append( "<p>" + business.telephone + "</p>");
}
});
for (var i in data.businesses) {
if(data.businesses[i].telephone)
$('body').append( "<p>" + data.businesses[i].telephone + "</p>");
}
Try this:
for (var i in data.businesses) {
if(data.businesses[i].telephone !== null and data.businesses[i].telephone !== undefined) {
$('body').append( "<p>" + data.businesses[i].telephone + "</p>");
}
}