Underscore.js _.zip() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Array

Definition

Merges the values of each array with the values at the corresponding position (official Underscore docs). Useful when separate data sources are coordinated through matching indexes. Stable Array helper — not deprecated.

Pass the required arguments shown below. Underscore array helpers usually return a new value — check whether the source array is mutated.

Syntax

Call _.zip. Start with this line.

Underscore
_.zip(*arrays)
CallWhat it does
_.zip(*arrays)Primary signature.
_.zip(...)Call with the arguments your case needs.

Load Underscore with import _ from "underscore" (or the UMD CDN build) so these helpers are available as _.

Library declarations
Underscore
_.zip(*arrays)

Parameters

ParameterDescription
*arraysRequired. Arrays to merge by index

Return Value

Return ValueDescription
*New array of tuples (one per index)

Underscore.js Examples

Example 1 — Official Docs Zip

Merge names, ages, and flags into one row per person.

Underscore
_.zip(
  ["moe", "larry", "curly"],
  [30, 40, 50],
  [true, false, false]
);
// → [["moe", 30, true], ["larry", 40, false], ["curly", 50, false]]
Try It Yourself

How It Works

  1. Three columns. Names, ages, and flags share the same indexes.
  2. Index 0. Take first from each → ["moe", 30, true].
  3. Next indexes. Same for larry and curly.
  4. Shape. Three arrays of length three → three tuples of length three.

Example 2 — Pair Two Arrays

The simplest zip — one tuple per matching index.

Underscore
var letters = ["a", "b", "c"];
var numbers = [1, 2, 3];

_.zip(letters, numbers);
// → [["a", 1], ["b", 2], ["c", 3]]
Try It Yourself

How It Works

  1. Aligned sources. Both arrays have length 3.
  2. Pair by index. "a" with 1, "b" with 2, and so on.
  3. Sources safe. letters and numbers are unchanged.
  4. Undo. _.unzip on the result restores the two columns.

Example 3 — Zip Then Build an Object

Zip for tuples; use _.object when you want a key/value map.

Underscore
var keys = ["moe", "larry", "curly"];
var ages = [30, 40, 50];

_.zip(keys, ages);
// → [["moe", 30], ["larry", 40], ["curly", 50]]

_.object(keys, ages);
// → { moe: 30, larry: 40, curly: 50 }
Try It Yourself

How It Works

  1. Zip. Builds an array of [key, value] pairs.
  2. Object. _.object(keys, ages) builds a plain object instead.
  3. Pick by need. Tuples for lists/tables; objects for lookup by name.
  4. Same alignment. Both helpers assume matching indexes.

Example 4 — Uneven Lengths

Result length follows the longest array; shorter ones leave undefined.

Underscore
_.zip(["a", "b", "c"], [1, 2]);
// → [["a", 1], ["b", 2], ["c", undefined]]
Try It Yourself

How It Works

  1. Longest wins. Three letters → three rows.
  2. Short column. Numbers only cover indexes 0 and 1.
  3. Gap. Row for "c" gets undefined as the second value.
  4. JSON note. JSON.stringify may show that gap as null.

Browser & Runtime Support

_.zip ships with Underscore.js (1.x). It runs anywhere Underscore runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install underscore.

✓ Stable · Underscore 1.x

_.zip()

Available in [email protected] (UMD / ESM). Works in evergreen browsers and current Node LTS when Underscore is loaded.

100% With Underscore 1.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.zip Underscore 1.x+

Bottom line: Safe for production once Underscore is on the page or in your bundle. Not a native browser API — load Underscore first. Prefer a pinned CDN version (e.g. [email protected]).

Frequently Asked Questions

_.zip(*arrays) merges arrays by matching index into sub-arrays (tuples). Example: _.zip(['a','b'], [1,2]) returns [['a',1],['b',2]].
As many as you need. _.zip is variadic — pass arrays one after another, e.g. _.zip(a, b, c).
The result length matches the longest array. Missing positions from shorter arrays become undefined.
Use _.unzip (alias _.transpose). It splits the zipped rows back into column arrays.
_.zip groups values into tuples by index. _.object builds a plain object from keys and values. Use _.object when you want key/value pairs.
No. It returns a new array of sub-arrays and leaves the inputs unchanged.

Next: _.unzip()

Split grouped rows back into separate column arrays — the inverse of _.zip().

_.unzip() tutorial →

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.

10 people found this page helpful