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].ratingstops withCannot 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
Mapkeeps any key. ASetkeeps each value once. - Use
?.only where a part may be missing. 0 ?? "unrated"gives0, and0 || "unrated"gives"unrated", so??keeps a rating of zero and the||operator replaces it.