Lodash is a JavaScript utility library for processing collections and objects with reusable functional operations. It replaces many manual loops with concise, declarative code and exposes its functions through the global _ object. section 3.0 section 3.3
Use Lodash’s core collection operations to transform, combine, and select data:
- Use _.map to apply a function to every element and return an equally sized array. section 3.3
- Use reduce to accumulate a collection into one result, such as country counts. section 3.3
- Use filter with a predicate to keep only elements satisfying a condition. section 3.3
- Chain operations with _(data).map(...).reduce(...) to separate data transformation from control flow. section 3.0 section 3.3
Select and transform people
const bornIn1903 = person => person.birthYear === 1903; _(persons) .filter(bornIn1903) .map(person => person.fullname) .join(' and '); // 'John von Neumann and Alonzo Church' The filter selects matching records, map extracts their names, and join formats the result. section 3.3
const p1 = new Person('Haskell', 'Curry', '111-11-1111');
p1.address = new Address('US');
p1.birthYear = 1900;
const p2 = new Person('Barkley', 'Rosser', '222-22-2222');
p2.address = new Address('Greece');
p2.birthYear = 1907;
const p3 = new Person('John', 'von Neumann', '333-33-3333');
p3.address = new Address('Hungary');
p3.birthYear = 1903;
const p4 = new Person('Alonzo', 'Church', '444-44-4444');
p4.address = new Address('US');
p4.birthYear = 1903;
Browse the person and address fixtures used to demonstrate Lodash collection transformations and statistics. section 3.3
