Published
Edited
Nov 10, 2019
Importers
Also listed in…
util
Insert cell
Insert cell
data = table(demoData)
Insert cell
Insert cell
function table(arrayOfRecords) {
const keys = Object.keys(arrayOfRecords[0]);
const table = html`<table>`;

const thead = html`<thead>`;
table.appendChild(thead);
thead.appendChild(html`<th>index`);
keys.forEach(key => {
thead.appendChild(html`<th>${key}`);
});

const tbody = html`<tbody>`;
table.appendChild(tbody);
arrayOfRecords.forEach((record, index) => {
const tr = html`<tr>`;
tbody.appendChild(tr);
tr.appendChild(html`<th>${index}`);
keys.forEach(key => {
tr.appendChild(html`<td>${record[key]}`);
});
});

// TODO: click to edit
return table;
}
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more