I am trying to insert my array data into a table that I have created. This is my code to put the data into arrays:
const theAccounts = GetAccountsArray();
console.log(theAccounts);
const theIds = [];
const theNames = [];
for(var theAccount in theAccounts)
{
theNames.push(theAccounts[theAccount]["Name"]);
theIds.push(theAccounts[theAccount]["Id"]);
}
This is my table:
<tr>
<th>Account Id</th>
<th>Account Name</th>
</tr>
<tr>
<td> theIds </td>
<td> theNames </td>
</tr>
</table>
</td>
TheNames and TheIds represent where I want the data to be.
This is what I did to display the table using @Bizoon 's suggestion:
<table id ="theTable" style="width: 100%; border: 1px solid black; ">
</table>
var theTable = "";
theTable +="<tr>";
theTable += "<th style='border: 1px solid black'>Account Id</th>";
theTable += "<th style='border: 1px solid black'>Account Name</th>";
theTable += "</tr>";
for (var i in theAccounts)
{
theTable += "<tr>";
theTable += "<td style='border: 1px solid black'>" +
theAccounts[i]["Id"] + "</td>" +
"<td style='border: 1px solid black'>" + theAccounts[i]["Name"] + "</td>";
theTable += "</tr>";
document.getElementById("theTable").innerHTML = theTable;
}
Do let me know if there is a better way to do this.