Lodash _.zipObject() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

Builds a plain object from two parallel arrays: property names and values. Like _.fromPairs, but keys and values live in separate arrays (same idea as fromPairs(zip(props, values))). Part of Lodash 4.x Array.

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

Syntax

Call _.zipObject on an array. Start with this line.

Lodash
_.zipObject([props=[]], [values=[]])
CallWhat it does
_.zipObject([props=[]], [values=[]])Primary signature.
_.zipObject(array)Call with an array argument.

Prefer import zipObject from "lodash/zipObject" when you want a smaller bundle.

Library declarations
Lodash
_.zipObject([props=[]], [values=[]])

Parameters

ParameterDescription
propsOptional. Property names; default []
valuesOptional. Matching values; default []

Return Value

Return ValueDescription
*New plain object

Lodash Examples

Example 1 — Official: Two Keys

Pair matching-length arrays into one object.

Lodash
_.zipObject(["a", "b"], [1, 2]);
// → { a: 1, b: 2 }
Try It Yourself

How It Works

  1. Props. Keys are "a" and "b".
  2. Values. Matching values are 1 and 2.
  3. Assign. Index 0 → a: 1; index 1 → b: 2.
  4. Result. A new plain object with both properties.

Example 2 — Headers and Cells

Turn column headers and one data row into a record.

Lodash
_.zipObject(["name", "score"], ["ada", 100]);
// → { name: "ada", score: 100 }
Try It Yourself

How It Works

  1. Headers. name and score become property names.
  2. Cells. "ada" and 100 fill those slots.
  3. Align. Same index means “this header owns this cell.”
  4. Use. Common after reading CSV / table columns.

Example 3 — More Keys Than Values

Missing values become undefined.

Lodash
_.zipObject(["x", "y", "z"], [10]);
// → { x: 10, y: undefined, z: undefined }
Try It Yourself

How It Works

  1. Three keys. Object size follows props.length.
  2. One value. Only x gets 10.
  3. Pad. y and z are set to undefined.
  4. JSON tip. JSON.stringify omits keys whose value is undefined.

Example 4 — Duplicate Keys

Repeated property names behave like repeated assignments — last wins.

Lodash
_.zipObject(["role", "role"], ["viewer", "admin"]);
// → { role: "admin" }
Try It Yourself

How It Works

  1. First pass. role = "viewer".
  2. Second pass. Same key overwritten with "admin".
  3. One property. Only the final value remains.
  4. Tip. Deduplicate props first if you need every value kept.

Example 5 — Extra Values Are Ignored

Values beyond the last key do not appear on the object.

Lodash
_.zipObject(["a"], [1, 2, 3]);
// → { a: 1 }

_.zipObject([], [1, 2]);
// → {}
Try It Yourself

How It Works

  1. One key. Only index 0 is assigned → a: 1.
  2. Leftovers. 2 and 3 have no key → dropped.
  3. Empty props. No keys means an empty object.
  4. Safe. Neither case throws.

Browser & Runtime Support

_.zipObject is a Lodash 4.x Array helper. It runs anywhere Lodash runs — modern browsers (via CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 4.x

_.zipObject()

Available in [email protected] full builds and the lodash/zipObject modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.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
_.zipObject Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import zipObject from "lodash/zipObject" for smaller builds. Not a native browser API — load Lodash first.

Frequently Asked Questions

_.zipObject(props, values) builds a plain object by pairing each property name from props with the value at the same index in values.
No. It returns a new object. The keys and values arrays stay unchanged.
Missing values become undefined for those keys. Extra values beyond the last key are ignored.
Assignments run in order — the last value for that property name wins.
fromPairs takes [[key, value], ...] rows. zipObject takes two parallel arrays: one of keys and one of values. Same idea as fromPairs(zip(keys, values)).
Use import zipObject from "lodash/zipObject" or require("lodash/zipObject") for tree-shaking. Full build: import _ from "lodash" then _.zipObject.

Next: _.zipObjectDeep()

Build nested objects from property-path keys and values.

_.zipObjectDeep() 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