Underscore.js Collection Methods

About This Index
This page is the Underscore.js Collections index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn the Underscore overview on /underscore-js. Use this page when you need a collection API such as _.each(), _.map(), or _.filter().
Start with _.each(), then _.map(), _.filter(), and _.reduce()—then browse the rest by category.
How to Call a Collection Method
Pass a list (array or object) as the first argument; iteratees receive (value, indexOrKey, list):
const nums = [1, 2, 3, 4];
const people = [
{ name: "moe", age: 40 },
{ name: "larry", age: 50 }
];
_.each(nums, function (n) { console.log(n); });
_.map(nums, function (n) { return n * 2; }); // [2, 4, 6, 8]
_.filter(nums, function (n) { return n % 2 === 0; }); // [2, 4]
_.reduce(nums, function (sum, n) { return sum + n; }, 0); // 10
_.pluck(people, "name"); // ["moe", "larry"]
_.groupBy(people, "age"); // { 40: [...], 50: [...] } Underscore.js Collection Methods Table
All collection method guides in this Underscore.js tutorial series (25 tutorials).
Getting Started
4 methodsCore iterators — each, map, and left/right reduce.
| Method | Description | Tutorial |
|---|---|---|
_.each() | Iterates a list (array or object), calling iteratee for each value (alias: _.forEach). | Try it |
_.map() | Produces a new array by transforming each value (alias: _.collect). | Try it |
_.reduce() | Folds a list into a single value from left to right (alias: _.foldl / _.inject). | Try it |
_.reduceRight() | Right-associative reduce — folds from last element to first (alias: _.foldr). | Try it |
Search & Filter
5 methodsFind matches, keep or reject values, and match property bags.
| Method | Description | Tutorial |
|---|---|---|
_.find() | Returns the first value that passes a predicate (alias: _.detect). | Try it |
_.filter() | Returns values that pass a predicate (alias: _.select). | Try it |
_.where() | Returns values that contain all of the key–value pairs in properties. | Try it |
_.findWhere() | Returns the first value that matches all key–value pairs in properties. | Try it |
_.reject() | Returns the values that fail a predicate — the opposite of filter. | Try it |
Test Membership
3 methodsAsk whether all, any, or a specific value is present.
Extract & Aggregate
4 methodsInvoke methods, pluck properties, and find min/max.
| Method | Description | Tutorial |
|---|---|---|
_.invoke() | Calls the named method on each value with optional arguments. | Try it |
_.pluck() | Extracts a list of property values — a convenient map shorthand. | Try it |
_.max() | Returns the maximum value, optionally by an iteratee. | Try it |
_.min() | Returns the minimum value, optionally by an iteratee. | Try it |
Organize
4 methodsSort, group, index, and count by an iteratee.
| Method | Description | Tutorial |
|---|---|---|
_.sortBy() | Returns a sorted copy ranked by iteratee criteria. | Try it |
_.groupBy() | Groups values into an object keyed by the iteratee result. | Try it |
_.indexBy() | Indexes values into an object keyed by the iteratee — one value per key. | Try it |
_.countBy() | Counts values grouped by the iteratee result. | Try it |
Sample & Convert
5 methodsShuffle, sample, convert to arrays, measure size, and partition.
| Method | Description | Tutorial |
|---|---|---|
_.shuffle() | Returns a shuffled copy using a Fisher–Yates style shuffle. | Try it |
_.sample() | Picks a random element, or n random elements. | Try it |
_.toArray() | Creates a real array from an iterable or array-like object. | Try it |
_.size() | Returns the number of values in the list (array length or object keys). | Try it |
_.partition() | Splits values into two arrays — [pass, fail] — by a predicate. | Try it |
Frequently Asked Questions
Start with _.each()
Open the iteration guide—syntax, examples, and FAQs.
14 people found this page helpful
