Lodash _.zipWith() method

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

What you’ll learn

  • How _.zipWith(...arrays, iteratee) fuses aligned slots with your combiner.
  • Why skipping the iteratee reproduces _.zip() tuples.
  • How this differs from _.unzipWith() when data starts as rows versus columns.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Skim _.zip() first—zipWith is the same alignment story with an optional reducer per index.

  • You can write pure iteratees without depending on external mutable state.
  • You can open Try-it labs or run snippets locally.

Overview

_.zipWith removes the intermediate tuple step when you already know how to merge each aligned slice—sums for ledger columns, string concat for labels, or library helpers like Math.max.

Per-index combine

Each row invokes your iteratee once with the gathered arguments.

Zip-compatible

Drop the iteratee and Lodash behaves like plain zip.

Immutable columns

Sources remain untouched for alternate combine strategies.

Syntax

javascript
_.zipWith(...arrays, [iteratee])
  • arrays: two or more collections aligned by index.
  • iteratee: optional; receives the aligned elements at each index and returns the combined output.
  • Returns: new array with one entry per aligned row.
1

Add pairwise entries

Ledger-like columns reduce to running totals per row without allocating inner arrays.

javascript
import zipWith from "lodash/zipWith";

zipWith([1, 2], [10, 20], (a, b) => a + b);
// → [11, 22]
Try it Yourself
2

Label each numeric slot

Use any deterministic combine—strings, objects, or helpers—as long as arity matches column count.

javascript
import zipWith from "lodash/zipWith";

zipWith(["score", "bonus"], [100, 25], (label, n) => `${label}:${n}`);
// → ["score:100", "bonus:25"]
Try it Yourself
3

Math.max across three arrays

Lodash feeds each aligned triple into Math.max, producing row-wise maxima without nested loops.

javascript
import zipWith from "lodash/zipWith";

zipWith([1, 8], [4, 3], [2, 9], Math.max);
// → [4, 9]
Try it Yourself

📋 _.zipWith vs zip, unzipWith, zipObject

APIOutputUse case
_.zipWith(...arrays, iteratee)Combined scalars/objectsSkip tuple allocation when you already know the reducer
_.zip(...arrays)TuplesKeep arrays grouped per row
_.unzipWith(array, iteratee)Column aggregatesStart from zipped rows, pivot, then fold
_.zipObject(props, values)Plain objectKeys column plus values column

Pitfalls to avoid

Arity

Iteratee signature drift

Adding another column changes argument positions—keep iteratees variadic or validate lengths first.

Ragged

undefined gaps

Shorter arrays inject undefined into your iteratee—guard before numeric math.

Hot

Heavy closures

Very hot loops may prefer tight native loops; zipWith shines when readability wins.

❓ FAQ

No. Lodash returns a new array of combined values; originals stay unchanged.
Always last: _.zipWith(...arrays, iteratee). Omitting the iteratee falls back to standard _.zip tuple behavior.
Lodash passes the aligned elements from each array at the current index—two arrays yield (a, b), three arrays yield (a, b, c), etc., with undefined where an array is shorter.
zipWith starts from parallel columns and merges forward per row; unzipWith pivots existing tuples into columns before folding.
Use import zipWith from "lodash/zipWith" or require("lodash/zipWith") for tree-shaken bundles.

Summary

Did you know?

Iteratee placement matches other Lodash *With helpers—the combiner is always last after every array argument.

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