JavaScript · Senior · Question 39 of 75
What does Object.groupBy(users, u => u.role) do?
- ✓Correct answer: Returns an object: key - role, value - array of users
- 2Sorts the original users array by the
rolefield - 3Removes users with duplicate roles from the array
Explanation
Object.groupBy (ES2024) replaces the typical reduce for grouping. The result is an object with a null prototype. If keys aren't strings, use Map.groupBy.