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

246
Vistas
jquery dynamic table render properly

I am new to jquery, I am trying to display dynamic table with jquery. But when I call below

jQuery.each(data, function(index, value) {
    value_split = value.slice(',');
    for(var i=0;i<value_split.length;i++){
        $("#table").append("<tr><td>" + value_split[i] + "</td></tr>");
    }
});

I am splitting because it's comma separated list. I get data like

First name
Last Name
Age
Sam
Don
23

How can I get in proper format with 3 headers and details in below row like normal table

yes I'm slicing becuase data is object e.g. Object {headers: Array[6], values: Array[6]}

sorry it's object not list

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You probably wanted to create the row outside the inner loop, otherwise you'll get a new row for each value you append.

var data = [
    "Sam, Don, 23",
    "Jane, Doe, 40"
];

jQuery.each(data, function(index, value) {
    var value_split = value.split(',');
    var tr = $('<tr />');
    
    for(var i=0;i<value_split.length;i++){
        tr.append( $('<td />', {text : value_split[i]}) );
    }
    
    $("#table").append(tr);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id="table">
    <tr><th>First Name</th><th>Last Name</th><th>Age</th></tr>
</table>

about 4 years ago · Santiago Trujillo 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