Arrays and Iteration
Arrays are where most JavaScript work happens. Build them, change them safely, describe transformations with map, filter and reduce instead of loops, sort without the classic traps, and reach for Set, Map and iterators when a plain array stops being the right shape.
What you will be able to do
- Create, read and reshape arrays without tripping over
lengthor holes - Choose between a mutating method and its non-mutating twin on purpose
- Replace most loops with a readable map, filter or reduce chain
- Sort correctly with a comparator, including multi-key and locale-aware sorts
- Pick the right collection for the job: array, Set, Map or a lazy iterator
Lessons
- Array Basics — An array is an object with numeric keys and a
lengththat always sits one past the highest index you have written. (10 min) - Adding and Removing — Work at the end of an array when you can:
pushandpoptouch one slot,shiftandunshiftmove every slot. (10 min) - map, filter and reduce — Stop writing loops. Describe the transformation: same length, fewer items, or one value. (16 min)
- Searching and Testing — Ask for the element with
find, for its position withfindIndex, and for a yes or no answer withsomeandevery. (11 min) - Sorting — A comparator answers one question: should
acome beforeb? Negative means yes, positive means no, zero means leave them as they are. (12 min) - Copying, Slicing and Flattening — If the method name is a verb in the past tense (
toSorted,toReversed), it hands you a copy. Otherwise assume it edits your array. (11 min) - Sets — A Set is a bag of unique values with instant membership checks and no indexes. (10 min)
- Maps — A Map is a dictionary whose keys can be anything, whose order you can trust, and whose size you can read. (11 min)
- Iterables and Iterator Helpers — An iterable is anything that can hand you a
next(); an iterator helper builds a pipeline that pulls one value at a time instead of building whole arrays. (13 min) - Typed Arrays and Binary Data — An ArrayBuffer is raw bytes; a typed array is a fixed-width window onto those bytes. (10 min)