Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
how do i build a table dynamically in this scenario

I have a variable which contains an array of arrays. It is parsed code from an excel file.

I want to upload my file and build the table, ive tried it like this:

tabela.forEach((elem, index) => {
  console.log(elem[0], index[1])
  const row = tableBody.insertRow(index)
  const employeeCell = row.insertCell(0)
  let content = document.createTextNode(elem[0])
  employeeCell.appendChild(content)
})

and like this:

for (let i = 1; i < tabela.length; i++) {
  const row = tableBody.insertRow(tabela[1])
  const employeeCell = row.insertCell(0)
  let content = document.createTextNode(tabela[0])
  employeeCell.appendChild(content)
}

but I get strange results with both.

I really want to understand what Im doing but am having issues.

The variable tabela is an array of 13 elements, each element is an array with 7 elements.

does anybody know what im doing wrong how to make it so i build a whole table from the parsed code from "tabela" variable?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You need to loop through the elements of row to add a cell for each element.

tabela.forEach(elem => {
  const row = tableBody.insertRow();
  elem.forEach(item => {
    const cell = row.insertCell();
    cell.innerText = item;
  });
})

about 4 years ago · Juan Pablo Isaza Denunciar

0

The following demo shows how you can accomplish your task using jQuery.

const tablea = [
    [30,45,2,9,0],
    [455,65,0,5,78],
    [1,1,4,4,6]
];
let $tableBody = $('#xdata tbody');
$tableBody.html(
    tablea.map(row => $('<tr/>').html(
        row.map(cell => $('<td/>').html( cell ))
    ))
);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="xdata"><tbody></tbody></table>

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda