Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function generateTable (elements) {
- const keys = [...new Set(elements.flatMap(el => Object.keys(el)))]
- return `
- <table>
- <thead>
- <tr>${keys.map(key => "<th>" + key + "</th>").join("")}</tr>
- </thead>
- <tbody>
- ${elements.map(el => {
- return "<tr>" + keys.map(key => "<th>" + el[key] + "</th>").join("") + "</tr>"
- }).join("")}
- </tbody>
- </table>
- `;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement