I’m trying to make a table using a DOM, but i’m having a trouble with this arrangement of the data.
I have an array..
let myData = [
{
options: "Option 1",
details: [
{
type: "Big Letters",
value: [
{name: "A"},
{name: "B"},
{name: "C"}
]
},
{
type: "Small Letters",
value: [
{name: "a"},
{name: "b"},
{name: "c"}
]
},
//Other codes here...
]
},
{
options: "Option 2",
details: [
{
type: "Numbers",
value: [
{name: 1},
{name: 2},
{name: 3},
{name: 4},
{name: 5}
]
},
//Other codes here...
]
},
//Other codes here...
];
Then i create a loop using forEach function and show the output using innerHTML. But the arrangement of data was messy. So i try to set up the rowspan but still messy(It seems their is lacking on my codes.
My fuction is…
let html ="<table border='1'>";
html +=`
<tr>
<th>Options</th>
<th>Types</th>
<th>Values</th>
</tr>`;
myData.forEach((item) => {
html += "<tr>";
html += `<td rowspan="${item.details.length}">${item.options}<td>`;
item.details.forEach((item2) => {
html += `<td rowspan="${item2.value.length}">${item2.type}</td>`
item2.value.forEach((item3) => {
html += `<td>${item3.name}</td>`
html += "</tr>";
})
})
})
html += "</table>";
document.body.innerHTML = html;
Here is my current output:
I would like my table look like this.
Is there any way to achieve this output?
Thank’s for your help.


