tengo una función que recibe un array y con los datos de dicha array debería crear una tabla mostrando los datos que contiene, pero no funciona, si alguien podría decirme cual es el error del código me seria de gran ayuda
Código:
function createTable(){
let users = createUsers();
let body = document.getElementsByTagName("body")[0];
let table = document.createElement("table");
let tblBody = document.createElement("tbody");
for(let i = 0; i < users.length; i++){
let row = document.createElement("tr");
let cellName = document.createElement("td");
let txtCellName = document.createTextNode(users[i].name);
cellName.appendChild(txtCellName);
row.appendChild(cellName);
let cellLastName = document.createElement("td");
let txtCellLastName = document.createTextNode(users[i].lastName);
cellLastName.appendChild(txtCellLastName);
row.appendChild(cellLastName);
let cellAge = document.createElement("td");
let txtCellAge = document.createTextNode(user[i].age);
cellAge.appendChild(txtCellAge);
row.appendChild(cellAge);
tblBody.appendChild(row);
}
table.appendChild(tblBody);
body.appendChild(table);
table.setAttribute("border", "2");
}