I am using JavaScript to produce a HTML table printing out the elements of a 2D array. I have an array that is used to create the Headers (columnNames) and an array to print the contents of each row (dataArray). So far I have:
function addTable(columnNames, dataArray) {
var x = document.createElement("TABLE");
x.setAttribute("id", "myTable");
document.body.appendChild(x);
var y = document.createElement("TR");
y.setAttribute("id", "myTr");
document.getElementById("myTable").appendChild(y);
//add column names
for (i = 0; i < columnNames.length; i++) {
var th = document.createElement("TH");
var columns = document.createTextNode(columnNames[i]);
th.appendChild(columns);
document.getElementById("myTr").appendChild(th);
}
And this gives me a table:

However i now want to loop through my 2d array “dataArray” and print out everything into 12 rows. I have the algorithm below but this only works for one row. Can anyone help me out please?
column = 0;
var y2 = document.createElement("TR");
y2.setAttribute("id", "myTr2");
document.getElementById("myTable").appendChild(y2);
while(column < 8){
var th2 = document.createElement("TD");
var date2 = document.createTextNode(dataArray[0][column]);
th2.appendChild(date2);
document.getElementById("myTr2").appendChild(th2);
column++;
}

I know im missing some sort of rows loop but have trialed and error'd lots of different algorithms so far with no luck. I want to have 12 rows for example. I used a 0 for the 1st array index just so i could display something but id ideally want that value to increment to a max number.