Hello! The title itself says my problem.
html
<table id="tabela">
<thead>
<tr>
<th>Nome</th>
<th>Idade</th>
<th>Profissão</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
js
const pessoas = [
{ nome: 'João', idade: 25, profissao: 'Engenheiro' },
{ nome: 'Maria', idade: 30, profissao: 'Médica' },
{ nome: 'Pedro', idade: 35, profissao: 'Professor' },
{ nome: 'Mauricio', idade: 45, profissao: 'Laboratorista' },
{ nome: 'Mauro', idade: 46, profissao: 'Vendedor' },
{ nome: 'Miguelzim', idade: 43, profissao: 'Vigilante' },
{ nome: 'Shulipa', idade: 16, profissao: 'Estudante' },
{ nome: 'Deusa', idade: 68, profissao: 'Aposentada' },
];
function preencherTabela() {
try {
const tabela = document.querySelector('#tabela tbody');
pessoas.forEach(pessoa => {
const linha = document.createElement('tr');
const colunaNome = document.createElement('td');
const colunaIdade = document.createElement('td');
const colunaProfissao = document.createElement('td');
colunaNome.textContent = pessoa.nome;
colunaIdade.textContent = pessoa.idade;
colunaProfissao.textContent = pessoa.profissao;
linha.appendChild(colunaNome);
linha.appendChild(colunaIdade);
linha.appendChild(colunaProfissao);
tabela.appendChild(linha);
});
} catch (err) {console.log(err) }
}
preencherTabela();
Can anyone point me to a solution?