Lodash _.unzip() method

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

What you’ll learn

  • How _.unzip(array) pivots row-wise tuples into column-wise arrays.
  • Why this helper pairs naturally with _.zip() when reshaping tabular data.
  • When zipWith, _.unzipWith(), or manual map columns deserve a different tool.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Comfort nesting arrays ([[a, b], [c, d]]) keeps the mental model crisp—each inner array is one logical row before the pivot.

  • You can picture matrices as rows of cells read left-to-right.
  • You can open Try-it labs or run snippets locally.

Overview

_.unzip helps when APIs deliver zipped tuples—coordinates paired as rows, CSV chunks as arrays—and you need independent arrays per column for charting, validation, or broadcasting.

Pivot rows → cols

Each tuple index becomes its own output array preserving encounter order.

Non-destructive shell

Outer arrays are new; inner element references stay tied to the source tuples.

Zip symmetry

Think of unzip as undoing zip when both sides use consistent rectangular data.

Syntax

javascript
_.unzip(array)
  • array: grouped collection—typically an array of tuples produced by hand or by zip.
  • Returns: array of columns; column i collects the ith element from every tuple.
1

Split paired tuples into two columns

Names and scores arrive as rows—unzip separates them into parallel arrays.

javascript
import unzip from "lodash/unzip";

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

Three-wide tuples

Wider CSV-style rows fan out into three aligned arrays—great before passing columns into chart constructors.

javascript
import unzip from "lodash/unzip";

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

Round-trip with _.zip

Zip merges standalone arrays into tuples; unzip restores the originals when lengths stay aligned.

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

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

📋 _.unzip vs zip, zipWith, unzipWith

APIDirectionUse case
_.unzip(array)Rows → columnsPivot zipped tuples without touching elements
_.zip(...arrays)Columns → rowsInterleave parallel arrays into tuples
_.zipWith(...arrays, iteratee)Columns → rowsCombine tuple slots with a reducer instead of keeping arrays
_.unzipWith(array, iteratee)Rows → custom foldUnzip then immediately collapse each column via iteratee

Pitfalls to avoid

Flat

Flatten confusion

unzip preserves tuple boundaries—reach for flatten or native flatMap when you need one contiguous array.

Ragged

Uneven rows

Shorter tuples introduce undefined placeholders—sanitize before numeric math or serialization guards.

Ref

Shared references

Mutating objects inside an output column mutates the originals—clone first when isolation matters.

❓ FAQ

No. Lodash builds fresh arrays for each column while reusing the original element references inside those columns.
An array whose elements are treated as rows—typically inner arrays or array-like tuples you previously produced with _.zip or parallel iterators.
Lodash pads missing slots with undefined so every output column reaches the maximum row length encountered.
zip takes separate arrays (columns) and merges them into rows; unzip accepts rows and splits them back into columns.
Use import unzip from "lodash/unzip" or require("lodash/unzip") for tree-shaken bundles.

Summary

Did you know?

_.unzip is the structural inverse of _.zip()—think pivoting spreadsheet rows into columns 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