Loading video player…

Working With Nested Data (Overview)

Welcome to Working With Nested Data! Real data has lists inside records, and records inside lists. Looping over the outer list doesn’t visit the lists inside it. Reading through a missing part can crash your program.

In this course, you’ll build a year-end report for the Riverside Book Club from their reading log. Run with node report.js, the finished report counts books per genre, picks each member’s favorite, totals each author’s books, and averages each genre’s ratings:

Language: Text
The Riverside Book Club: Year-End Report

Books per genre
  sci-fi: 6
  fantasy: 2
  memoir: 4
  mystery: 2
  fiction: 1

Favorites
  Maya: Kindred (5), "Couldn't put it down."
  Jamal: The Thursday Murder Club (5), "Funny and clever."
  Rosa: Parable of the Sower (5), "Hard to read, harder to forget."
  Dev: Project Hail Mary (4), (no review)
  Hannah: Educated (5), (no review)
  Luis: no books yet

Books per author (7 authors)
  Octavia E. Butler: 3
  Andy Weir: 3
  Madeline Miller: 2
  Tara Westover: 2
  Richard Osman: 2
  Trevor Noah: 2
  Celeste Ng: 1

Average rating per genre
  sci-fi: 4.5
  fantasy: 1.5
  memoir: 4
  mystery: 4.5
  fiction: 4

The report comes from the club’s log, an array of six members. Each member has a list of books. Each book is a record with a rating, and only some have a review. Luis’s list is empty. The report has to handle all of that. So in each lesson, you first read the shape of the data, to see which loop reaches which part, then write the loop.

What You’ll Learn

By the end of this course, you’ll be able to:

  • Run loops inside loops, and loop over an object’s keys and values
  • Read the shape of nested data, and loop through every level
  • Reduce a list to one value, and count and collect with Map and Set
  • Group records, summarize each group, and handle missing parts
  • Build the book club’s year-end report, and explain the choices behind it

Before You Start

You should know functions, loops, arrays, and objects in Node.

You should also know how to hand arrow functions to array methods, and when two names share one object. You’ll need a current Node LTS, a terminal, and any editor.

This is the third course on the Intermediate JavaScript path, and it stands on its own.

How the Course Works

You’ll read text lessons, watch short videos, and run every example in your terminal. Each section ends with a browser exercise, checked by tests. In the project, you’ll build the report, then talk your code through in a chat with the RealJS mentor, opened from the lesson page. A quiz closes the course.

Next, in Run Loops Inside Loops, you’ll print one member’s ratings as rows of stars.

Download

Course Slides (.pdf)

831.0 KB
Download

Sample Code (.zip)

21.7 KB

00:00 Welcome to Working With Nested Data.

00:04 Real data has lists inside records, and records inside lists. Looping over the outer list doesn’t visit the lists inside it. Reading through a missing part can crash your program.

00:16 The Riverside Book Club keeps a reading log for the year. Here’s the year-end report you’ll build from it. It counts books per genre, picks each member’s favorite, totals each author’s books, and averages each genre’s ratings.

00:31 The report comes from the club’s log, an array of six members. Each member has a list of books. Each book is a record with a rating, and only some have a review.

00:43 Luis’s list is empty. The report has to handle all of that. So in each lesson, you first read the shape of the data, to see which loop reaches which part, then write the loop.

00:58 By the end, you’ll run loops inside loops, and loop over an object’s keys and values. You’ll read the shape of nested data, and loop through every level. You’ll reduce a list to one value, and count and collect with Map and Set.

01:14 You’ll group records, summarize each group, and handle missing parts. And you’ll build the book club’s year-end report, and explain the choices behind it.

01:25 Before you start, you should know functions, loops, arrays, and objects in Node, how to hand arrow functions to array methods, and when two names share one object.

01:36 You need a current Node LTS, a terminal, and any editor. It’s the third course on the Intermediate JavaScript path, and it stands on its own.

01:48 You’ll read text lessons, watch short videos, and run every example in your terminal. Each section ends with a browser exercise, checked by tests. In the project, you’ll build the report, then talk your code through in a chat with the RealJS mentor.

02:05 A quiz closes the course. Next, in Run Loops Inside Loops, you’ll print one member’s ratings as rows of stars.

Become a Member to join the conversation.