JSFiddle - React, Tailwind, and code Playground
HTML
<table id="table">
<thead>
<th id="publicationDate"></th>
<th id="contracted"></th>
<th id="contracting"></th>
<th id="id"></th>
<th id="objectBriefDescription"></th>
<th id="initialContractualPrice"></th>
<th id="signingDate"></th>
</thead>
<tbody>
</tbody>
</table>
JavaScript
var orderedObject = {
publicationDate: "28-02-2014",
contracted: "Servicash - Equipamentos Electrónicos, Lda.",
contracting: "Banco de Portugal",
id: 994738,
objectBriefDescription: "Consumíveis de papel para tratamento de dinheiro",
initialContractualPrice: "12.945,50 €",
signingDate: "28-02-2014"
};
var unorderedObject = {
id: 994738,
objectBriefDescription: "Consumíveis de papel para tratamento de dinheiro",
initialContractualPrice: "12.945,50 €",
signingDate: "28-02-2014",
publicationDate: "28-02-2014",
contracted: "Servicash - Equipamentos Electrónicos, Lda.",
contracting: "Banco de Portugal",
};
var toManyPropertiesObject = {
id: 994738,
objectBriefDescription: "Consumíveis de papel para tratamento de dinheiro",
initialContractualPrice: "12.945,50 €",
signingDate: "28-02-2014",
publicationDate: "28-02-2014",
contracted: "Servicash - Equipamentos Electrónicos, Lda.",
contracting: "Banco de Portugal",
newProp: "ignored",
newProp1: "ignored",
newProp2: "ignored",
};
var toFewPropertiesObject = {
id: 994738,
objectBriefDescription: "Consumíveis de papel para tratamento de dinheiro",
initialContractualPrice: "12.945,50 €",
contracted: "Servicash - Equipamentos Electrónicos, Lda.",
contracting: "Banco de Portugal",
};
printObjectInTable(orderedObject, "table");
printObjectInTable(unorderedObject, "table");
printObjectInTable(toManyPropertiesObject, "table");
printObjectInTable(toFewPropertiesObject, "table");
/*
* Generates a table row and populates it with the information from the object passed to the function.
* After that adds the row to the table body of the table identified by the ID.
*/
function printObjectInTable(objectToIterate, tableID) {
var thChildren = document.getElementById(tableID).getElementsByTagName("th"),
childrenLength = thChildren.length,
tr = document.createElement("tr");
for (var i = 0; i <...