I found a few other posts that seem to address this using jquery, but I would like to use javascript only. I would like to create a table using bootstrap but can't seem to figure out how to append new data to the table. It is creating the header, but then just dumping the items I want as rows below the table header.
html
<div id = specificFailureCountTable-js></div>
js
let filterText = 'machines';
let tableData = document.getElementById("specificFailureCountTable-js");
let data = [["machineA",15],["machineB",54],["machineC",26]];
//set header of table
tableData.innerHTML = `
<table class="table table-striped" id = "myTable">
<thead>
<tr>
<th scope="col">${filterText}</th>
<th scope="col">Count</th>
</tr>
</thead>
<tbody>
`;
//create//append rows
for(i = 0; i < data.length; i++){
tableData.innerHTML = tableData.innerHTML +
`<tr>
<th scope="row">${i}</th>
<td>${data[i][0]}</td>
<td>${data[i][1]}</td>
</tr>`
}
//close off table
tableData.innerHTML = tableData.innerHTML +
`</tbody>
</table>`
;
forloop it want's to create as many tables as there aredata.[i]objects. That's why I figured I had to break it up into multiple strings.