function prepRibbonData(jsonData) { let resList = []; let resJson = { x: [], y: [], z: [], }; const L = jsonData.length; var startVal = 2; var currentMonth = 0; for (var d = 0; d < L; d++) { let tmpDate = new Date(jsonData[d].x); // let datum = tmpDate.getDate(); // gets the day of the month 1...31 let month = date.getMonth(); // gets the month as numeric value if (currentMonth === month) { resJson.x.push([startVal, startVal + 1]); resJson.y.push([tmpDate, tmpDate]); resJson.z.push([jsonData[d].y, jsonData[d].y]); } else { resList.push(resJson); resJson.x = []; resJson.y = []; resJson.z = []; currentMonth += 1; startVal += 2; } } // end of for loop // add results for last month as else statement will not be reached for the december // as the condition d < L will be true before the condition currentMonth === month can be evaluated // resList.push(resJson); return resList; }