Created
September 26, 2023 14:37
-
-
Save mthh/1bad8ae747ae68c11ff5982a66de9da4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeTable(tab) { | |
const table = document.createElement('table'); | |
table.style = 'border: none; border-collapse: collapse;'; | |
const tbody = document.createElement('tbody'); | |
Object.keys(tab[0]) | |
.forEach((key) => { | |
const tr = document.createElement('tr'); | |
const td1 = document.createElement('td'); | |
const td2 = document.createElement('td'); | |
td1.style = 'border-left: none; padding: 10px;'; | |
td2.style = 'border-left: 1px solid #000; padding: 10px;'; | |
td1.textContent = key; | |
td2.textContent = tab[0][key]; | |
tr.appendChild(td1); | |
tr.appendChild(td2); | |
tbody.appendChild(tr); | |
}); | |
table.appendChild(tbody); | |
return table; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment