Lodash _.unzipWith() method

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

What you’ll learn

  • How _.unzipWith(array, iteratee) pivots tuples then collapses each column in one call chain.
  • Why iteratees receive a spread of values sourced from every row at the same column index.
  • When plain _.unzip() (keep arrays) or manual map beats a fused helper.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Understand _.unzip() first—unzipWith runs the same pivot, then replaces each column array with your reducer output.

  • You can read variadic functions such as (...vals) => vals.reduce(fn).
  • You can open Try-it labs or run snippets locally.

Overview

_.unzipWith shines when telemetry batches arrive zipped yet analytics needs scalar aggregates per dimension—sums, maxima, joins—without an intermediate map pass.

Pivot + fold

One helper expresses both regrouping and per-column reduction.

Variadic iteratees

Column arity mirrors tuple width—wider rows mean more parameters.

Immutable shell

Inputs remain untouched while you emit fresh reduced columns.

Syntax

javascript
_.unzipWith(array, [iteratee])
  • array: tuples to pivot—same expectations as _.unzip.
  • iteratee (optional): invoked per column with spread arguments from each row at that index.
  • Returns: array whose length equals tuple width; entries are iteratee outputs (or inner arrays when iteratee omitted).
1

Sum each column with _.add

Zipped numeric rows collapse into totals per dimension—ideal for quick rollup previews.

javascript
import unzipWith from "lodash/unzipWith";
import add from "lodash/add";

unzipWith(
  [
    [1, 10, 100],
    [2, 20, 200]
  ],
  add
);
// → [3, 30, 300]
Try it Yourself
2

Maximum per column

Spread arguments into Math.max when you need winners across aligned readings.

javascript
import unzipWith from "lodash/unzipWith";

unzipWith(
  [
    [1, 50],
    [9, 12],
    [4, 77]
  ],
  (...vals) => Math.max(...vals)
);
// → [9, 77]
Try it Yourself
3

Merge string columns

Pairwise tokens become deterministic labels—iteratees are not limited to math helpers.

javascript
import unzipWith from "lodash/unzipWith";

unzipWith(
  [
    ["a", "x"],
    ["b", "y"]
  ],
  (left, right) => left + ":" + right
);
// → ["a:b", "x:y"]
Try it Yourself

📋 _.unzipWith vs unzip, zipWith, manual map

APIOutput per columnBest when
_.unzipWith(array, iteratee)Reduced scalar/objectPivot plus aggregate in one shot
_.unzip(array)Array of column valuesYou still need independent arrays for plotting pipelines
_.zipWith(...arrays, iteratee)Row tuples via forward zipSources start as parallel arrays, not rows
unzip then map(columnFn)Custom per stepDebugging intermediate pivots or mixing iterators

Pitfalls to avoid

Ragged

undefined slots

Uneven tuples flow through as missing arguments—guard reduce logic before calling strict numeric APIs.

Arity

Tuple width drift

Changing column counts changes iteratee arity overnight—keep schemas stable or branch inside the reducer.

Perf

Heavy iteratees

Expensive reducers run once per column but still allocate spreads—profile huge batches.

❓ FAQ

No. Lodash returns a new array of folded column values; tuple references inside comparisons remain shared unless your iteratee clones them.
Lodash spreads each regrouped column into your iteratee—the first tuple contributes the first argument, the second tuple the next, and so on (undefined appears for ragged rows).
Lodash falls back to behaving like plain _.unzip—each column stays an array rather than a reduced scalar.
zipWith merges parallel arrays using an iteratee per index slot; unzipWith starts from tuples, pivots to columns, then reduces each column.
Use import unzipWith from "lodash/unzipWith" or require("lodash/unzipWith") for tree-shaken bundles.

Summary

  • Purpose: _.unzipWith(array, iteratee) pivots tuples then folds each column via your iteratee.
  • Fallback: skip the iteratee when you only need raw columns—plain unzip stays clearer.
  • Next: Lodash _.without(), _.unzip() (previous), or the array methods hub.
Did you know?

Treat unzipWith as _.unzip() followed by a per-column reducer—mirroring how zipWith inserts an iteratee into the forward zip path.

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