Upon receiving the JSON data, my task is to showcase three dates on a webpage categorized as: onsaleDate
, focDate
, and unlimitedDate
. These specific dates are stored as "values" under the keys "date". Presently, I am fetching these dates using dates[0].date
, dates[1].date
, and dates[2].date
. The challenge lies in the fact that not all instances of dates
will contain all three types - onsaleDate
, focDate
, and unlimitedDate
. How can I verify the presence of these date types before assigning them to a variable for display on the page? Would a conditional loop be necessary? Is it feasible to 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"
}
]