Advertisement
svetlyoek

Untitled

Jun 1st, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. function solve(json) {
  2. let text = JSON.parse(json);
  3.  
  4. let result = "";
  5.  
  6. result += "<table>\n";
  7. result += " <tr>";
  8.  
  9. for (const key in text[0]) {
  10. if (text[0].hasOwnProperty(key)) {
  11. result += `<th>${key}</th>`;
  12. }
  13. }
  14.  
  15. result += "</tr>\n";
  16.  
  17. for (let i = 0; i < text.length; i++) {
  18. const element = text[i];
  19. result += " <tr>";
  20.  
  21. for (const value in element) {
  22. let cellValue = String(element[value])
  23. .replace(/&/gim, '&amp;')
  24. .replace(/</gim, '&lt;')
  25. .replace(/>/gim, '&gt;')
  26. .replace(/"/gim, '&quot;')
  27. .replace(/'/gim, '&#39;');
  28.  
  29. result += `<td>${cellValue}</td>`;
  30. }
  31.  
  32. result += "</tr>\n"
  33. }
  34.  
  35. result += "</table>";
  36.  
  37. console.log(result);
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement