Lodash _.zip() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.zip(...arrays) merges aligned indices into row tuples.
  • Why this pairs naturally with _.unzip() when reshaping tabular data.
  • When zipWith, _.unzipWith(), or plain map is clearer than raw tuples.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Picture each argument as a spreadsheet column—zip walks down the rows and bundles cells together.

  • You are comfortable with nested arrays representing rows of cells.
  • You can open Try-it labs or run snippets locally.

Overview

_.zip shines when parallel arrays describe the same entities—IDs beside labels beside flags—and you need row records for rendering tables, validation batches, or immutable updates.

Columns → rows

Index i of every argument becomes one tuple at output index i.

Non-destructive

Inputs stay untouched; tuples reference the same element objects as before.

Unzip symmetry

Pair it with unzip for reversible pivots when lengths line up.

Syntax

javascript
_.zip(...arrays)
  • arrays: two or more collections aligned by index—each acts like one column.
  • Returns: array of tuples; row i bundles index i from every argument (undefined where an argument is shorter).
1

Zip two parallel columns

Names and scores live in separate arrays—zip stitches each pair into one tuple.

javascript
import zip from "lodash/zip";

zip(["ada", "bob"], [100, 85]);
// → [["ada", 100], ["bob", 85]]
Try it Yourself
2

Three-wide rows

Pass three aligned arrays to produce triples—useful before mapping rows into chart points or table rows.

javascript
import zip from "lodash/zip";

zip(
  ["north", "south", "east"],
  [12, 8, 15],
  [true, false, true]
);
// → [["north", 12, true], ["south", 8, false], ["east", 15, true]]
Try it Yourself
3

Unequal lengths and round-trip

Shorter columns pad with undefined; combining zip with unzip restores rectangular columns when shapes match.

javascript
import zip from "lodash/zip";
import unzip from "lodash/unzip";

zip([1, 2, 3], ["a"]);
// → [[1, "a"], [2, undefined], [3, undefined]]

unzip(zip([1, 2], ["a", "b"]));
// → [[1, 2], ["a", "b"]]
Try it Yourself

📋 _.zip vs unzip, zipWith, unzipWith

APIDirectionUse case
_.zip(...arrays)Columns → rowsBundle aligned indices into tuples
_.zipObject(props, values)Columns → objectPair key/value arrays into one plain object
_.unzip(array)Rows → columnsSplit tuples back into parallel arrays
_.zipWith(...arrays, iteratee)Columns → reduced rowsFuse slots with a combiner instead of inner arrays
_.unzipWith(array, iteratee)Rows → custom foldUnzip then collapse each column immediately

Pitfalls to avoid

Flat

Flatten confusion

zip nests tuples—reach for flatten or concat when you need one linear array.

Ragged

undefined fillers

Mismatched lengths introduce holes—strip or default them before math or JSON APIs that reject undefined.

Ref

Shared references

Mutating objects pulled into tuples still affects the source arrays—clone when isolation matters.

❓ FAQ

No. Lodash returns a new array of tuples while keeping references to the original elements inside each tuple.
Lodash pads missing slots with undefined so every output row reaches the length of the longest input.
zip takes separate column arrays and interleaves them into rows; unzip accepts rows of tuples and splits them back into columns.
When you want to combine aligned slots with an iteratee (sum pairs, merge objects) instead of keeping inner arrays.
Use import zip from "lodash/zip" or require("lodash/zip") for tree-shaken bundles.

Summary

Did you know?

_.zip is the structural inverse of _.unzip()—think grouping spreadsheet columns into rows without mutating the originals.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

6 people found this page helpful