I have data in an object that I'm trying to display in a table. Unfortunately, all my columns are displaying undefined.
  var fifadata = [{
    "fields": ["id", "country", "alternate_name", "fifa_code", "group_id", "group_letter", "wins", "draws", "losses", "games_played", "points", "goals_for", "goals_against", "goal_differential"]
  }, {
    "id": 1,
    "country": "Brazil",
    "alternate_name": null,
    "fifa_code": "BRA",
    "group_id": 1,
    "group_letter": "A",
    "wins": 4,
    "draws": 1,
    "losses": 2,
    "games_played": 7,
    "points": 13,
    "goals_for": 11,
    "goals_against": 14,
    "goal_differential": -3
  }, {
    "id": 2,
    "country": "Croatia",
    "alternate_name": null,
    "fifa_code": "CRO",
    "group_id": 1,
    "group_letter": "A",
    "wins": 1,
    "draws": 0,
    "losses": 2,
    "games_played": 3,
    "points": 3,
    "goals_for": 6,
    "goals_against": 6,
    "goal_differential": 0
  }, {
    "id": 3,
    "country": "Mexico",
    "alternate_name": null,
    "fifa_code": "MEX",
    "group_id": 1,
    "group_letter": "A",
    "wins": 2,
    "draws": 1,
    "losses": 1,
    "games_played": 4,
    "points": 7,
    "goals_for": 5,
    "goals_against": 3,
    "goal_differential": 2
  }];
var body = document.getElementsByTagName('body')[0];
var table = document.createElement("table");
var thead = document.createElement("thead");
var tbody = document.createElement("tbody");
var th = document.createElement("th");
var caption = document.createElement('caption');
var cap = document.createTextNode("Game Results List");
caption.appendChild(cap);
caption.style.fontWeight = "900";
table.appendChild(caption);
body.appendChild(table);
table.style.border = "1px dashed red";
table.style.borderSpacing = "1px";
table.style.textAlign = "center";
//table head(correct)
for (i = 0; i < 1; i++) {
  var tr = document.createElement("tr");
  thead.appendChild(tr);
  table.appendChild(thead);
  for (j = 0; j < fifadata[0].fields.length; j++) {
    var th = document.createElement("th");
    var keyname = fifadata[0].fields[j];
    var tm = document.createTextNode(keyname);
    th.appendChild(tm);
    tr.appendChild(th);
    th.style.border = "1px dashed blue";
    th.style.padding = "5px";
  }
}
//table body(incorrect).
//I need to use a dynamically created property(i.e. keyinfo) in "var text"
//i.e.fifadata[i].keyinfo; should change into fifadata[1].ID when it is 
//excecuted.
for (i = 1; i < fifadata.length; i++) {
  var tr = document.createElement("tr");
  tbody.appendChild(tr);
  table.appendChild(tbody);
  for (j = 0; j < fifadata[0].fields.length; j++) {
    var td = document.createElement("td");
    var keyinfo = fifadata[0].fields[j];
    var test = fifadata[i].keyinfo;
    var tn = document.createTextNode(test);
    td.appendChild(tn);
    tr.appendChild(td);
    td.style.border = "1px dashed green";
    td.style.padding = "2px";
  }
}If all goes well it should create a table from the JSON data. Can my code be modified slightly? Is there an easier why to do it?
var test=fifadata[i].keyinfo;should have beenvar test=fifadata[i][keyinfo];It's helpful if you reduce your code examples down to the specific part that is giving you trouble. You pretty much identified the issue by explaining that it showsundefined, so it would be helpful if people didn't have to dig through that code to get the part where the desired text is assigned.