Category

Collection

Utilities for working with collections and iterables

12 utilities available

groupBy

Creates an object composed of keys generated from the results of running each element of collection through iteratee. The order of grouped values is determined by the order they occur in collection.

keyBy

Creates an object composed of keys generated from the results of running each element of collection through iteratee. The corresponding value of each key is the last element responsible for generating the key.

partition

Creates an array of elements split into two groups, the first of which contains elements predicate returns truthy for, the second of which contains elements predicate returns falsy for.

sortBy

Creates an array of elements, sorted in ascending order by the results of running each element through each iteratee. This method performs a stable sort.

orderBy

This method is like sortBy except that it allows specifying the sort orders of the iteratees. If orders is unspecified, all values are sorted in ascending order.

countBy

Creates an object composed of keys generated from the results of running each element of collection through iteratee. The corresponding value of each key is the number of times the key was returned by iteratee.

shuffle

Creates an array of shuffled values, using a version of the Fisher-Yates shuffle.

sample

Gets a random element from collection.

sampleSize

Gets n random elements at unique keys from collection up to the size of collection.

every

Checks if predicate returns truthy for all elements of collection. Iteration is stopped once predicate returns falsy.

some

Checks if predicate returns truthy for any element of collection. Iteration is stopped once predicate returns truthy.

includes

Checks if value is in collection. If collection is a string, it's checked for a substring of value.