I've the following JSON result. I have to display onto a web page three dates with types: onsaleDate
, focDate
, unlimitedDate
. These fields are "values" to the keys "date". I'm currently accessing the dates by using dates[0].date
, dates[1].date
and dates[2].date
. The problem, however, is that some of the other dates
results do not necessarily have all of the three items with types onsaleDate
, focDate
, unlimitedDate
. How can I check that these three date types
exist before I assign them to a variable for display onto the page? Do I need a conditional loop? Can I use hasOwnProperty
for nested items?
"results": [
"dates": [
{
"type": "onsaleDate",
"date": "2011-10-12T00:00:00-0400"
},
{
"type": "focDate",
"date": "2011-09-12T00:00:00-0400"
},
{
"type": "unlimitedDate",
"date": "2012-12-18T00:00:00-0500"
},
{
"type": "digitalPurchaseDate",
"date": "2012-05-01T00:00:00-0400"
}
]