16_matrix_to_html_table.js 529 B

12345678910111213141516171819202122232425
  1. let multiplyTable = [];
  2. for (let i = 1; i <= 10; i++) {
  3. multiplyTable[i] = [];
  4. for (let j = 1; j <= 10; j++) {
  5. multiplyTable[i][j] = j * i;
  6. }
  7. }
  8. const htmlTable = (arr) => {
  9. let result = "<table>";
  10. for(let i = 1; i < arr.length; i++) {
  11. result += "<tr>";
  12. for(let j = 1; j < arr[i].length; j++){
  13. result += `<td>${arr[i][j]}</td>`;
  14. }
  15. result += "</tr>";
  16. }
  17. result += "</table>";
  18. return result;
  19. }
  20. document.querySelector('body').insertAdjacentHTML('beforeend', htmlTable(multiplyTable));