Array Methods: map, filter, reduce and Friends
Learn Array Methods: map, filter, reduce and Friends (Phase 6 · Array Methods, Map, Set (Essential), JavaScript) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Transforming arrays without loops • map(fn) returns a new array of the same length with each item transformed. • filter(fn) keeps the items for which fn returns truthy. • reduce(fn, initial) folds the array into one value (a sum, an object, a new array). • find / findIndex return the first match; some / every return a boolean; forEach just runs code and returns nothing.