JS

HOW TO CREATE HTML TABLE FROM JAVASCRIPT ARRAY

ONLY NEED A <DIV> CONTAINER <div id="wrap"></div>

THE HTML

01

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

CREATE HTML TABLE STRING var perrow = 2,        html = "<table><tr>";

JS CREATE HTML TABLE (A)

02

LOOP ARRAY TO ADD CELLS for (var i=0; i<data.length; i++) {   html += `<td>${data[i]}</td>`;

JS CREATE HTML TABLE (B)

03

  BREAK INTO NEXT ROW   var next = i+1;   if (next%perrow==0 &&    next!=data.length)   { html += "</tr><tr>";  } } html += "</tr></table>";

ATTACH HTML TO <DIV> document.getElementById("wrap") .innerHTML = html;

JS CREATE HTML TABLE (C)

04