Lodash Array Methods

About This Index
This page is the Lodash Arrays index for the tutorial track. Each row links to a full guide with syntax, examples, and FAQs.
Learn the Lodash overview on /lodash. Use this page when you need an array API such as _.chunk(), _.uniq(), or _.flatten().
Start with _.chunk(), then _.compact(), _.uniq(), and _.flatten()—then browse set ops and mutating helpers as needed.
How to Call an Array Method
Import a method or use the _ object—most helpers return a new array:
import _ from "lodash";
// or: import chunk from "lodash/chunk";
const nums = [1, 2, 3, 4, 5];
_.chunk(nums, 2); // [[1, 2], [3, 4], [5]]
_.compact([0, 1, false, 2, "", 3]); // [1, 2, 3]
_.uniq([1, 2, 1, 4, 1, 3]); // [1, 2, 4, 3]
_.flatten([1, [2, [3, [4]]]]); // [1, 2, [3, [4]]]
_.difference([2, 1], [2, 3]); // [1]
_.zip(["a", "b"], [1, 2]); // [["a", 1], ["b", 2]] Lodash Array Methods Table
All array method guides in this Lodash tutorial series (64 tutorials).
Getting Started
3 methodsChunk, clean falsy values, and concatenate arrays.
| Method | Description | Tutorial |
|---|---|---|
_.chunk() | Split an array into groups of a given size. | Try it |
_.compact() | Remove falsy values (false, null, 0, "", undefined, NaN). | Try it |
_.concat() | Create a new array concatenating array with additional values. | Try it |
Ends & Slices
14 methodsRead ends, drop or take portions, and slice ranges.
| Method | Description | Tutorial |
|---|---|---|
_.head() | First element of an array (alias: _.first). | Try it |
_.last() | Last element of an array. | Try it |
_.nth() | Element at index n (supports negative indices). | Try it |
_.initial() | All but the last element. | Try it |
_.tail() | All but the first element. | Try it |
_.drop() | Drop n elements from the beginning. | Try it |
_.dropRight() | Drop n elements from the end. | Try it |
_.dropWhile() | Drop from the start while predicate returns truthy. | Try it |
_.dropRightWhile() | Drop from the end while predicate returns truthy. | Try it |
_.take() | Take n elements from the beginning. | Try it |
_.takeRight() | Take n elements from the end. | Try it |
_.takeWhile() | Take from the start while predicate is truthy. | Try it |
_.takeRightWhile() | Take from the end while predicate is truthy. | Try it |
_.slice() | Slice a portion of the array into a new array. | Try it |
Flatten & Pairs
5 methodsFlatten nests and convert pairs into objects.
| Method | Description | Tutorial |
|---|---|---|
_.flatten() | Flatten one level of nested arrays. | Try it |
_.flattenDeep() | Recursively flatten until no nested arrays remain. | Try it |
_.flattenDepth() | Flatten up to a given depth. | Try it |
_.fromPairs() | Build an object from key-value pairs. | Try it |
_.join() | Join elements into a string with a separator. | Try it |
Set Operations
16 methodsDifference, intersection, union, xor, uniq, and without.
| Method | Description | Tutorial |
|---|---|---|
_.difference() | Values from the first array not present in the others. | Try it |
_.differenceBy() | Like difference, but values compared after invoking iteratee. | Try it |
_.differenceWith() | Like difference, but uses a comparator for equality. | Try it |
_.intersection() | Values common to all given arrays. | Try it |
_.intersectionBy() | Intersection after mapping each element with iteratee. | Try it |
_.intersectionWith() | Intersection using a comparator. | Try it |
_.union() | Unique values from all arrays combined. | Try it |
_.unionBy() | Union after mapping with iteratee. | Try it |
_.unionWith() | Union using a comparator. | Try it |
_.uniq() | Unique values preserving first-occurrence order. | Try it |
_.uniqBy() | Unique by iteratee result. | Try it |
_.uniqWith() | Unique using a comparator for equality. | Try it |
_.without() | Exclude given values from the array (new array). | Try it |
_.xor() | Symmetric difference of arrays. | Try it |
_.xorBy() | Symmetric difference after iteratee. | Try it |
_.xorWith() | Symmetric difference with comparator. | Try it |
Mutating Helpers
8 methodsIn-place pull, remove, fill, and reverse — use carefully.
| Method | Description | Tutorial |
|---|---|---|
_.fill() | Fill elements with a value between start and end (mutates). | Try it |
_.pull() | Remove all occurrences of given values in place. | Try it |
_.pullAll() | Like pull, but accepts an array of values to remove. | Try it |
_.pullAllBy() | Like pullAll, but values compared after iteratee. | Try it |
_.pullAllWith() | Like pullAll, but uses a comparator. | Try it |
_.pullAt() | Remove elements at indexes and return them. | Try it |
_.remove() | Remove elements matching predicate; returns removed elements. | Try it |
_.reverse() | Reverse the array in place. | Try it |
Index & Search
12 methodsLocate values by equality, predicate, or sorted binary search.
| Method | Description | Tutorial |
|---|---|---|
_.indexOf() | First index of value using SameValueZero. | Try it |
_.lastIndexOf() | Last index of value, searching from the end. | Try it |
_.findIndex() | Index of the first element matching predicate. | Try it |
_.findLastIndex() | Index of the last element matching predicate. | Try it |
_.sortedIndex() | Lowest index to insert a value and keep sort order. | Try it |
_.sortedIndexBy() | Like sortedIndex, but compares iteratee(value). | Try it |
_.sortedIndexOf() | Like indexOf for sorted arrays (binary search). | Try it |
_.sortedLastIndex() | Highest index to insert a value and keep sort order. | Try it |
_.sortedLastIndexBy() | Like sortedLastIndex with iteratee. | Try it |
_.sortedLastIndexOf() | Like lastIndexOf for sorted arrays. | Try it |
_.sortedUniq() | Unique values from a sorted array. | Try it |
_.sortedUniqBy() | Unique by iteratee from a sorted array. | Try it |
Zip & Unzip
6 methodsPair rows, build objects from key lists, and unzip tuples.
| Method | Description | Tutorial |
|---|---|---|
_.zip() | Group elements by index across arrays. | Try it |
_.zipWith() | Zip arrays and combine tuples with iteratee. | Try it |
_.zipObject() | Build an object from keys and values arrays. | Try it |
_.zipObjectDeep() | Like zipObject, with support for nested paths. | Try it |
_.unzip() | Inverse of zip — regroup tuples into arrays. | Try it |
_.unzipWith() | Like unzip, then apply iteratee to regrouped values. | Try it |
Frequently Asked Questions
Start with _.chunk()
Open the chunking guide—syntax, examples, and FAQs.
16 people found this page helpful
