Based on Diego D's answer, I made a more scalable (extensible) function (primarily for my needs).
const players = [
{name: 'Player1', score: 10, id:'aaa', address: 'usa'},
{name: 'Player2', score: 7, id:'bbb', address: 'mars'},
{name: 'Player3', score: 3, id:'ccc', address: 'jupyter'},
];
const fullHeaders = Object.keys(players[0]); //use full header
const selectedHeaders = ['name', 'score']; //or filter as needed
const table1 = makeTable(fullHeaders, players);
const table2 = makeTable(selectedHeaders, players);
function makeTable(headers, players, target = document.body) {
const newTable = document.createElement("table");
const thead = document.createElement("thead");
for(header of headers) {
const th = document.createElement("th");
th.textContent = header;
thead.appendChild(th);
}
newTable.appendChild(thead);
for(player of players) {
const newRow = document.createElement("tr");
for(header of headers) {
const td = document.createElement("td");
td.textContent = player[header];
newRow.appendChild(td);
}
newTable.appendChild(newRow);
}
return target.appendChild(newTable);
}