What exactly did we do here?
The key is in the three
for-each statements that we used. One loops through the array of table header strings and appends a table cell (
th for header cells) element with each value to the
thead element's row. Then there are two nested
.forEach statements that do the same for each row in the body. We technically only have one row in the body right now, so we probably didn't need that messy double
for-each, but now all we have to do to add another row to the table is simply append another data array to the
rows variable. We'll talk a bunch more about
Array.prototype.forEach and other array functions in the next chapter.
This might seem like a lot of work for such a simple table, but the advantages of doing it ...