O'Reilly logo

Learning d3.js Data Visualization - Second Edition by Swizec Teller, Ændrew Rininsland

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 (td, or 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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required