Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

586
Visualizações
Populate Table with JSON Data - Vanilla JavaScript

I am writing a function that displays a json data from a REST API in a table. My data looks like the data below. I am currently getting undefined error. How Can I populate my table with this data? I am not too familiar with tables, and my confusion comes with how to iterate and then to append my data to the created elements.

Const data = [{
    name: "Adam",
    age: 10,
  },
  {
    name: "Suzy",
    age: 9,
  },
  {
    name: "wilson",
    age: 6,
  },
  {
    name: "nelson",
    age: 5,
  },
  {
    name: "hinny",
    age: 2,
  }
];

// This is what I have: 



const displayTable = (data) => {
  const table = document.createElement('table');

  const tbl = document.createElement('table');
  const thead = document.createElement('thead');
  const tb = document.createElement('tbody');
  const tr = document.createElement('tr');
  const th = document.createElement('th');
  const td = document.createElement('td');

  const name = data.map(function(e) {
    return e.name;
  });
  const age = data.map(function(e) {
    return e.age;
  });

  tr.innerHTML = name;
  tr.innerHTML = age
  thead.appendChild(tr)
  tbody.appendChild(tr)
  table.appendChild(tr)
};

I am trying to achieve something like the table below with the vertical line and all:

Example of table display

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda