Form the the table with json data

With keys as headers in the table..

const summary_data = [{ Geo: "US West", MeetingHash: "Hold/Uncategorized", count: 65 },
  { Geo: "NSU", MeetingHash: "Hold/Uncategorized", count: 9 },
  { Geo: "US East", MeetingHash: "Hold/Uncategorized", count: 3 }];
  var val = summary_data[0];
  var table = `<table><tr>`;
  Object.keys(val).forEach(function (key) {
     table += `<th>${key}</th>`;
  });
  table += '</tr>';
  for (var i in summary_data) {
     table += '<tr>';
     var val = summary_data[i];
     Object.keys(val).forEach(function (key) {
        table += `<td>${val[key]}</td>`;
     });
     table += '</tr>';
  }
  table += '</table>';
  console.log(table);
  $('body').html(table);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

Leave a Comment