Lodash _.zipObjectDeep() method

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

What you’ll learn

  • How _.zipObjectDeep(props, values) turns path strings into nested objects.
  • When _.zipObject() is safer (literal flat keys).
  • How bracket segments allocate arrays for tabular or list-shaped payloads.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Read _.zipObject() first—the deep variant only changes how each prop string is interpreted.

  • You can read simple Lodash property paths (a.b, a[0]).
  • You can open Try-it labs or run snippets locally.

Overview

_.zipObjectDeep helps when configuration rows or CSV columns arrive as dotted paths—avoid dozens of set calls by zipping paths with parallel value arrays in one pass.

Parsed paths

Each key walks or creates intermediate objects and arrays automatically.

ZipObject parity

Same padding and duplicate-key semantics as shallow zipObject.

Immutable sources

Inputs remain untouched for retries with different path lists.

Syntax

javascript
_.zipObjectDeep(props, values)
  • props: array of property path strings (Lodash path syntax).
  • values: aligned values—extras ignored; missing entries become undefined leaves.
  • Returns: new nested plain object materialized from the zipped paths.
1

Dotted paths merge under one parent

Separate path segments collapse into one nested record—ideal for flat env-style keys.

javascript
import zipObjectDeep from "lodash/zipObjectDeep";

zipObjectDeep(["user.name", "user.age"], ["Ada", 42]);
// → { user: { name: "Ada", age: 42 } }
Try it Yourself
2

Bracket indices build arrays

Numeric bracket steps allocate array slots—useful when importing spreadsheet rows as parallel objects.

javascript
import zipObjectDeep from "lodash/zipObjectDeep";

zipObjectDeep(["items[0].sku", "items[1].sku"], ["A1", "B2"]);
// → { items: [{ sku: "A1" }, { sku: "B2" }] }
Try it Yourself
3

zipObject keeps dotted keys flat

The shallow helper treats "a.b" as one literal key. The deep helper parses it into nested properties.

javascript
import zipObject from "lodash/zipObject";
import zipObjectDeep from "lodash/zipObjectDeep";

zipObject(["a.b", "a.c"], [1, 2]);
// → { "a.b": 1, "a.c": 2 }

zipObjectDeep(["a.b", "a.c"], [1, 2]);
// → { a: { b: 1, c: 2 } }
Try it Yourself

📋 _.zipObjectDeep vs zipObject, set, fromPairs

APIKeysUse case
_.zipObjectDeep(props, values)Parsed pathsBuild trees from parallel path/value columns
_.zipObject(props, values)Literal stringsOne shallow property per prop—dots stay in the key name
_.set(object, path, value)Single path per callMutate or clone-merge one branch at a time
_.fromPairs(pairs)First tuple slotNo automatic nesting unless keys themselves encode structure differently

Pitfalls to avoid

Path

Typos reshape trees

A stray dot creates an unintended subtree—validate paths when ingesting user-supplied strings.

Order

Overlapping assignments

Later zipped pairs can replace intermediate objects built earlier—sort paths carefully when merging fragments.

Flat

Need literal dotted keys?

Stick to zipObject when keys must remain flat strings like registry.io/port.

❓ FAQ

No. Lodash reads both arrays and returns a new nested object; inputs stay unchanged.
Same index pairing—only the key interpretation differs. Plain zipObject treats each prop string as a single literal key; zipObjectDeep parses property paths.
Use bracket notation such as items[0].id so Lodash allocates arrays at numeric segments.
Later assignments win; overlapping prefixes merge into shared parents until a value replaces an intermediate object.
Use import zipObjectDeep from "lodash/zipObjectDeep" or require("lodash/zipObjectDeep") for tree-shaken bundles.

Summary

Did you know?

Path strings follow the same rules as other Lodash utilities—dots traverse objects and bracket notation ([0], ["hyphen-key"]) builds arrays or awkward keys without hand-written reducers.

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