Lodash _.fromPairs() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Array

Definition

The inverse of _.toPairs: returns a plain object composed from key-value pairs. Part of Lodash 4.x Array (stable since 4.0.0).

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

Syntax

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

Lodash
_.fromPairs(pairs)
CallWhat it does
_.fromPairs(pairs)Primary signature.
_.fromPairs(array)Call with an array argument.

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

Library declarations
Lodash
_.fromPairs(pairs)

Parameters

ParameterDescription
pairsRequired. Array of [key, value] rows

Return Value

Return ValueDescription
*New plain object

Lodash Examples

Example 1 — Official: Basic Pairs

Each inner array supplies one key and one value.

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

How It Works

  1. Two rows. Official sample: [["a", 1], ["b", 2]].
  2. First assign. Property a gets 1.
  3. Second assign. Property b gets 2.
  4. Result. A new object — the pairs array is untouched.

Example 2 — Named Keys (Ages)

String keys become property names; values can be numbers.

Lodash
_.fromPairs([["fred", 30], ["barney", 40]]);
// → { fred: 30, barney: 40 }
Try It Yourself

How It Works

  1. Row shape. Each pair is [name, age].
  2. Assign fred. result.fred = 30.
  3. Assign barney. result.barney = 40.
  4. Use case. Handy when data arrives as table rows, not object literals.

Example 3 — Duplicate Keys (Last Wins)

If the same key appears twice, the later value replaces the earlier one.

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

How It Works

  1. First write. a is set to 1.
  2. Second write. Same key a is set to 2.
  3. Final object. Only one property remains: { a: 2 }.
  4. Tip. Sort or dedupe pairs first if you need a different merge rule.

Example 4 — Empty Array

No pairs means an empty object.

Lodash
_.fromPairs([]);
// → {}
Try It Yourself

How It Works

  1. Empty source. There are no rows to assign.
  2. Result. Lodash still returns a new {}.
  3. Safe. No throw — useful as a default when a parser yields no entries.
  4. Check. Use Object.keys(obj).length if you need to detect emptiness.

Example 5 — Round-Trip with _.toPairs

Convert an object to pairs, then back — shallow string keys round-trip cleanly.

Lodash
var original = { a: 1, b: 2 };

_.fromPairs(_.toPairs(original));
// → { a: 1, b: 2 }
Try It Yourself

How It Works

  1. Expand. _.toPairs turns { a: 1, b: 2 } into [["a",1],["b",2]].
  2. Fold. _.fromPairs rebuilds the object from those rows.
  3. New object. The result is a new reference, not the same as original.
  4. Limit. Prototype / symbol / nested path cases need other tools.

Browser & Runtime Support

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

✓ Stable · Lodash 4.0.0+

_.fromPairs()

Available in [email protected] full builds and the lodash/fromPairs modular import. Prefer Lodash 4.0.1+ so dotted keys are treated as literal names (fixed vs early 4.0.0 path bug).

100% With Lodash 4.0.1+
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
_.fromPairs Lodash 4.0.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import fromPairs from "lodash/fromPairs" for smaller builds. Native alternative: Object.fromEntries (ES2019) for iterables of entries.

Frequently Asked Questions

_.fromPairs(pairs) builds a new plain object from an array of [key, value] pairs. It is the inverse of _.toPairs for typical string-keyed objects.
No. Lodash reads the pairs and returns a new object. The input array is not modified.
Later pairs overwrite earlier ones. The last [key, value] for a given key wins.
Object.fromEntries accepts any iterable of entries (including Map). _.fromPairs expects an array of pair arrays and matches classic Lodash style.
_.zipObject(keys, values) takes two parallel arrays. _.fromPairs takes one array of [key, value] rows — better when pairs already travel together.
Use import fromPairs from "lodash/fromPairs" or require("lodash/fromPairs") for tree-shaking friendly bundles. Full build: import _ from "lodash" then _.fromPairs.

Next: _.head()

Get the first element of an array (or undefined if empty).

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