Form The The Table With Json Data
I want to form the table for the json data.I juct removed the quotation,comma and curly braces. and tried to add table for geo ,meeting hash and count.Now able to add only space.
Solution 1:
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);
<scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
Post a Comment for "Form The The Table With Json Data"