Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Working With Nested Data (Summary)

You’ve finished Working With Nested Data, and the Riverside Book Club has its year-end report. Every part of that report started from the log’s shape: an array of members, each an object with a list of books, each book an object whose review may be missing, and Luis’s list empty. A loop inside a loop gathered every book into one flat list, allBooks, fifteen in all, and the rest of the report came from there.

In This Course, You Learned How 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

Things to Remember

  • Draw the shape before you write the loop.
  • When log[1].book[0].rating stops with Cannot read properties of undefined (reading '0'), the message names [0], the step JavaScript tried next. The broken step is the one right before it, .book.
  • Pass .reduce() a starting value, and return the accumulator.
  • An object turns its keys into strings, but a Map keeps any key. A Set keeps each value once.
  • Use ?. only where a part may be missing.
  • 0 ?? "unrated" gives 0, and 0 || "unrated" gives "unrated", so ?? keeps a rating of zero and the || operator replaces it.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:00 You’ve finished Working With Nested Data. In this course, you learned how to run loops inside loops, and loop over an object’s keys and values. You learned how to read the shape of nested data, and loop through every level.

00:15 How to reduce a list to one value, and count and collect with Map and Set. How to group records, summarize each group, and handle missing parts. And you built the book club’s year-end report, and explained the choices behind it.

00:31 That report started from the log’s shape. The log is an array of members. Each member is an object with a list of books. Each book is an object, and its review may be missing.

00:44 Luis’s list is empty.

00:47 A loop inside a loop pushed every book into one flat list, fifteen in all. From there, reduce counted the books per genre. A loop kept each member’s best book, with a placeholder for a missing review.

01:03 A Set found seven different authors, and a Map counted their books. And grouping by genre gave each genre’s average.

01:13 Things to remember. Draw the shape before the loop. A path’s error names the step it tried next. The broken one is right before it. Pass reduce a starting value, and return the accumulator.

01:28 An object turns its keys into strings, but a Map keeps any key. A Set keeps each value once. Use optional chaining only where a part may be missing. And ?? keeps a rating of zero.

01:42 The || operator replaces it.

01:46 The RealJS reference has pages on Map, Set, and optional chaining.

01:53 Thanks for watching.

Become a Member to join the conversation.