Loading topic
Array.prototype.reduce or a plain loop. You will see this code in almost every older codebase. It also helps you see what Object.groupBy and Map.groupBy do for you, becau5 min readreduce, arrow functions with destructuring, and plain objects. It also builds on the previous chapter's hand-written reduce grouping. Here you will make a first Object.groupBy call, learn the shape of its result, and see the step-by-step process it foll4 min readObject.groupBy decides how your data is grouped. It runs once for each element and returns a key, and every element that gets the same key goes into the same group. This chapter covers the common kinds of key callback: reading a property, computing a label, combining sever4 min readObject.groupBy with a key callback. You should also know how plain objects inherit methods from Object.prototype, and how optional chaining (?.) and nullish coalescing (??) work. The topic here is one detail of the result that catches people out. 4 min readObject.groupBy puts its groups in a plain object, so every key becomes a string or a symbol. Map.groupBy takes the same two arguments, an iterable and a key callback, but returns a Map. A Map stores each key exactly as your callback returned it. A number stays a number, a boolean stays a boo4 min readMap.groupBy works: it takes an iterable and a key callback, and it returns a Map from each key to an array of elements. You should also know basic Map methods (get, has, keys) and the difference between primitive values and object references.5 min readObject.groupBy with a key callback and know that its result is a null-prototype object. You should also be comfortable with template literals, JSON.stringify, and the basics of Map.4 min readObject.groupBy returns a null-prototype object, and Map.groupBy returns a Map whose keys are compared with SameValueZero. You should also know how Object.groupBy converts keys to strings. Here we turn those facts into a decision. W5 min readObject.groupBy and Map.groupBy output into those summarie5 min readObject.groupBy and Map.groupBy on arrays, and that you know what an iterable is: an object with a Symbol.iterator method, which for...of and spread syntax can consume. Some familiarity with generator functions (function*) will also help.5 min readObject.groupBy and Map.groupBy, and that you understand the difference between primitive values and objects in JavaScript. In particular, you should know that assigning an object to a variable copies a reference to it, not the object itself.5 min read"2023" jumps ahead of "2025" even though 2025 appeared first in your data. This chapter explains the rules that decide the order, where Object.groupBy and5 min readObject.groupBy and Map.groupBy behave, including the null-prototype result and key coercion. It also assumes you can read a tsconfig.json and run Node.js from a terminal. It covers three things. First, where the methods are available. Second, how TypeS5 min readObject.groupBy and Map.groupBy throughout this tutorial. You may have wondered why they are called as Object.groupBy(items, fn) and not as items.groupBy(fn), the way you call map, filter, and reduce. This chapter explains how the design ended up static and what that choic5 min read