showing results for - "javascript foreach table"
Camilo
30 Mar 2020
1  function get_table(data) {
2    let result = ['<table border=1>'];
3    for(let row of data) {
4        result.push('<tr>');
5        for(let cell of row){
6            result.push(`<td>${cell}</td>`);
7        }
8        result.push('</tr>');
9    }
10    result.push('</table>');
11    return result.join('\n');
12  }
13
Giada
15 Sep 2016
1function createTable(tableData) {
2  var table = document.createElement('table');
3  var row = {};
4  var cell = {};
5
6  tableData.forEach(function(rowData) {
7    row = table.insertRow(-1); // [-1] for last position in Safari
8    rowData.forEach(function(cellData) {
9      cell = row.insertCell();
10      cell.textContent = cellData;
11    });
12  });
13  document.body.appendChild(table);
14}
15