I'm trying to create a table which changes dynamically. The number of its columns changes according to the number of days of the month (28, 29, 30, or 31).
I created the table manually (but the number of columns is fixed to 31):
https://i.sstatic.net/pAvPu.png
Here is the component in which I tried to select the number of columns manually according to the number of days of the current month (28,29,30,31), it shows nothing in the browser:
const Test = () => {
// Number of days in the current month
function daysInCurrentMonth() {
var now = new Date();
return new Date(now.getFullYear(), now.getMonth()+1, 0).getDate();
}
let a = daysInCurrentMonth();
return (
<div>
<table>
<tbody>
<tr>
{() => {
for(let i=1;i<=a;i++){
<td>{i}</td>
}
}}
</tr>
</tbody>
</table>
</div>
);
}
export default Test;
How can I use a for loop inside this code?