var obj = {
2: {
5: 15,
11: 220,
30: 70
},
3: {
1: 65,
4: 30,
30: 5
}
};
function daysInMonth(month, year) {
return (new Date(year, month, 0)).getDate();
}
var months = Object.keys(obj),
tbl = '<table>',
lineTop = '',
lineBot = '';
for(var i = 0; i < months.length; i++) {
lineTop = '<tr>';
lineBot = '<tr>';
for(var d = 1; d <= daysInMonth(months[i], 2016); d++) {
lineTop += '<th>' + d + '</th>';
if(obj[months[i]].hasOwnProperty(d)) {
lineBot += '<td class="has-val">' + obj[months[i]][d] + '</td>';
} else {
lineBot += '<td></td>';
}
}
lineTop += '</tr>';
lineBot += '</tr>';
tbl += lineTop + lineBot;
}
tbl += '</table>';
document.body.innerHTML = tbl;