← Node.js Foundations
9 / 25
Lesson 9 — Group records
Group a list by a field
APIs often return data grouped: all admins together, all users together. reduce can build an object where each key is a group and each value is a list. acc[key] ||= [] means "if this group does not exist yet, start it as an empty list".
acc["admin"] ||= [];
acc["admin"].push("A");
Why it matters: grouping is how raw rows become the sections of a report or a menu.
Want it another way?
Task
Inside reduce, push each user name into its role group. Then each group is logged.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
Test your knowledge
A quick 3-question quiz on this lesson — instant feedback.