i am having and json file wich is created dynamicaly.
For example
{
"users": [
{
"name": "Bill",
"surname": "Antony",
"userPoints": 121,
"wins": 11,
"nationality": "English"
},
{
"name": "George",
"surname": "Peter",
"userPoints": 1332,
"wins": 11
}
]
}
As you can see the second object is missing nationality field. So in my code when i am printing with JS Jquery (.each). I am having an 'undedified' print for the second user. How can i check this before it's printed?
EDIT: I am adding the way i am printing the data:
function displayData(array) {
var list = $("#list").empty();
$.each(array, function () {
$("ul").append('<li><span class="num">'+ if(this["nationality"]){ this["nationality"] }+'</span></li>');
});
}
if (user.nationality) { console.log(user.nationality)}