There are 3 arrays that need to be transferred to a table, the first is a two-dimensional array, the other is one-dimensional.

let table = document.createElement("TABLE") let tableBody = document.createElement("TBODY") table.appendChild(tableBody) let up = [ [17, 20, 29, 26, 25], [3, 4, 5, 15, 24], [19, 2, 22, 4, 13], [20, 27, 1, 17, 19]] let i = [15,15,15,15] let j = [11,11,11,11,16] // nxm размер двумерного массива, после последней // строки нужно вывести одномерный массив внутри таблицы, // после последнего столбца нужно вывести второй одномерный массив for (let row = 0; row < n; row++) { let tr = document.createElement("TR") tableBody.appendChild(tr) for (let col = 0; col < m; col++) { let td = document.createElement("TD") td.innerHTML = up[row][col] if (up[row][col] != 0) { td.innerHTML = up[row][col] } tr.appendChild(td) } } document.body.appendChild(table) // Результат должен быть // 17 20 29 26 25 15 // 3 4 5 15 24 15 // 19 2 22 4 13 15 // 20 27 1 17 19 15 // 11 11 11 11 16 
  • It would be nice if you gave examples of arrays, and showed how a table should be formed from them so that you can understand what your problem is. - Sergey Glazirin

1 answer 1

The easiest way to combine the arrays into one two-dimensional, and then display it in a table.

 let table = document.createElement("TABLE") let tableBody = document.createElement("TBODY") table.appendChild(tableBody) let up = [ [17, 20, 29, 26, 25], [3, 4, 5, 15, 24], [19, 2, 22, 4, 13], [20, 27, 1, 17, 19] ] let rigth = [15, 15, 15, 15] let down = [11, 11, 11, 11, 16] for (let i = 0; i < up.length; i++) { up[i].push(rigth[i]); } up.push(down); for (let i = 0; i < up.length; i++) { let tr = document.createElement("TR") tableBody.appendChild(tr); { for (let j = 0; j < up[i].length; j++) { let td = document.createElement("TD") td.innerHTML = up[i][j]; tr.appendChild(td) } } } document.body.appendChild(table) // Результат должен быть // 17 20 29 26 25 15 // 3 4 5 15 24 15 // 19 2 22 4 13 15 // 20 27 1 17 19 15 // 11 11 11 11 16 
 table, td { border: 1px solid black; }