Here is an extract of my json data
"availability":[
{
"hash":"820eRWiyq2Vy4Sk",
"arrival":"2019-12-01",
"departure":"2019-12-08",
"description":"",
"col1":"695",
"availability":"empty",
"availableRooms":"7",
"availableGuests":"16"
},
{
"hash":"8201ahPFdE28VUF",
"arrival":"2020-01-05",
"departure":"2020-01-12",
"description":"",
"col1":"695",
"availability":"empty",
"availableRooms":"7",
"availableGuests":"16"
},
{
and here is where I have got to with my limited, newly acquired knowledge of javascript template literals
success: function(data) {
myObj = data.chalets[0].availability;
console.log(myObj);
document.getElementById("app").innerHTML = `
<h2 class="section-title text-center-xs">Price & Availability</h2>
<div class="chalet-price-table">
<!-- chalet-price-row -->
<div class="chalet-price-row">
<div class="row-date" data-month="12">
<span><span>Dec '19</span></span>
</div>
<!-- row-days -->
${myObj.map(function(chalet) {
return `
<div class="row-days">
<div class="row-days-wrap">
<div class="day">
<span class="d">${chalet.arrival.slice(-2)}</span>
<span class="rooms-left">${chalet.availableRooms} Rooms Left</span>
<span class="price"><span class="only-price"><b>N/A</b></span><span class="inc-price"><b>£${chalet.col1}</b> per person</span></span>
<small class="was text-red"><span class="only-price"></span><span class="inc-price"></span></small>
<a data-chalet-id="26054" data-chalet-name="Chalet La Ferme dâElise" data-chalet-offer-day="14/12/2019" href="#" data-price="inc-price" data-toggle="modal" data-modal-class="modal-vertical-centered" data-modal-size="lg" data-target="#offer-enquiry-modal" class="btn btn-yellow"><i class="fa fa-angle-right"></i><i class="fa fa-angle-right"></i></a>
</div>
</div>
</div>
`
}).join('')}
<!-- row-days END -->
</div>
</div>
<p>Changeover day is Saturday.</p>
`
},
and here is the image of what is returned once formatted (top image)
So here is where I ask for some pointers please.
The Black box featuring Dec '19 is outside the loop and has been manually produced.
Firstly, how would I set about extracting the available months from the json? I am guessing
.arrival.slice(5, 7)
would play a part her. I suppose I then need to create a map of the original array for each of the available months, in my case just dec, jan and feb so that just the availability from each month comes after the relevant black boxed month as per the second part of the above image (in which the data has to be manually inserted!)