Build HTML Table from Object Array

PHOTO EMBED

Sat Nov 28 2020 17:34:58 GMT+0000 (Coordinated Universal Time)

Saved by @malcolm #javascript

var buildTable = function(tableId, tData) {
  var tableRef = document.getElementById(tableId);
  tData.forEach(dataObj => {
    var row = tableRef.insertRow(1);
    Object.values(dataObj).forEach(val => {
      var dataColumn = document.createElement("td");
      dataColumn.innerHTML = val;
      row.appendChild(dataColumn);
    });
  });
}
content_copyCOPY

Build an HTML table out of an array of objects in ascending order. All you have to do is change the headers of the table accordingly for this to work well.