I thought I could do the following to check if a data value was null
and then substitute something else.
$.ajax({
url: 'php/parsedjson.php',
dataType: 'json',
success: function(data) {
$.each(data, function(index, val) {
if (data[index].Manufacturers[0].Name != null){
var manufacturer = data[index].Manufacturers[0].Name;}
else{ var manufacturer ="MISSING"}
});
}
})
However, this throws an error Uncaught TypeError: Cannot read property 'Name' of undefined
when the data value is not supplied in the JSON.
How do you check if there is a value to prevent this from happening?