JS

CREATE HTML TABLE FROM ARRAY

(quick guide & examples)

EMPTY <TABLE> WRAPPER <table id="wrap"></table>

DUMMY TABLE & ARRAY

01

DUMMY ARRAY var data = ["alpaca", "birb", "cate", "doge"];

MANUAL HTML STRING

02

BUILD HTML TABLE (2 CELLS PER ROW) var perrow = 2, html = "<tr>"; data.forEach((v, i) => {   html += `<td>${v}</td>`;   var next = i + 1;   if (next%perrow==0 && next!=data.length)    { html += "</tr><tr>"; } }); html += "</tr>";

ADD TO TABLE document.getElementById("wrap") .innerHTML = html;

INSERT ROWS & CELLS

02

TABLE, ROW, CELL var table = document.getElementById ("wrap"), row = table.insertRow(), cell, perrow = 2;

BUILD HTML TABLE (2 CELLS PER ROW) data.forEach((v, i) => {   cell = row.insertCell();   cell.innerHTML = value;   var next = i + 1;   if (next%perrow==0 && next!=data.length)    { row = table.insertRow(); } });