Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

244
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!