Print out Javascript array in table

前端 未结 3 1189
北恋
北恋 2020-12-10 19:50

I have this array:

var employees = [
{ \"firstName\":\"John\" , \"lastName\":\"Doe\" }, 
{ \"firstName\":\"Anna\" , \"lastName\":\"Smith\" }, 
{ \"firstName\         


        
3条回答
  •  伪装坚强ぢ
    2020-12-10 20:47

    var table = document.createElement("table");
    for (var i = 0; i < employees.length; i++) {
      var row = table.insertRow(-1);
      var firstNameCell = row.insertCell(-1);
      firstNameCell.appendChild(document.createTextNode(employees[i].firstName));
      var lastNameCell = row.insertCell(-1);
      lastNameCell.appendChild(document.createTextNode(employees[i].lastName));
    }
    document.body.appendChild(table);
    

提交回复
热议问题