Advertisement
LukeSavefrogs

Untitled

Apr 16th, 2024
683
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function generateTable (elements) {
  2.     const keys = [...new Set(elements.flatMap(el => Object.keys(el)))]
  3.  
  4.     return `
  5.         <table>
  6.             <thead>
  7.                 <tr>${keys.map(key => "<th>" + key + "</th>").join("")}</tr>
  8.             </thead>
  9.             <tbody>
  10.                 ${elements.map(el => {
  11.                     return "<tr>" + keys.map(key => "<th>" + el[key] + "</th>").join("") + "</tr>"
  12.                 }).join("")}
  13.             </tbody>
  14.         </table>
  15.     `;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement