I have written three for loops for displaying data on the screen using JavaScript. How can I simplify the following code?
My Json Format:
{
"result": {
"type": "SUCCESS",
"data": [{
"monthName": "July",
"monthId": 7,
"weeks": [{
"days": [{
"day": "Sunday",
"date": "07/31/2016"
}],
}],
}],
}
}
var monthObj = response.result.data;
for (var i = 0; i < monthObj.length; i++) {
for (var t = 0; t < monthObj[i].weeks.length; t++) {
for (var s = 0; s < monthObj[i].weeks[t].days.length; s++) {
}
}
}
This is my loop, here I have written 3 loops.
Is there any easy way to simplify these loops?
"data" : ["07/31/2016"], which can give you all the other info when converted to a Date object. It would reduce everything down to one loop. (depending on what you're doing with those dates...)