Underscore.js _.object() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Array

Definition

Converts arrays into objects. Pass either a single list of [key, value] pairs, or a list of keys and a list of values (official Underscore docs). 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 _.object. Start with this line.

Underscore
_.object(list, [values])
CallWhat it does
_.object(list, [values])Primary signature.
_.object(...)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
_.object(list, [values])

Parameters

ParameterDescription
listRequired. Keys array, or array of [key, value] pairs
valuesOptional. Matching values when list is keys only

Return Value

Return ValueDescription
*New plain object

Underscore.js Examples

Example 1 — Official: Keys and Values

Pair each key with the value at the same index — same call as the docs.

Underscore
_.object(["moe", "larry", "curly"], [30, 40, 50]);
// → { moe: 30, larry: 40, curly: 50 }
Try It Yourself

How It Works

  1. Two lists. Names are keys; ages are values at matching indexes.
  2. Index 0. "moe" maps to 30.
  3. Next slots. Same pairing for larry and curly.
  4. Result. A new plain object — the arrays stay unchanged.

Example 2 — Official: List of Pairs

Pass one array of [key, value] pairs when data already looks like that.

Underscore
_.object([
  ["moe", 30],
  ["larry", 40],
  ["curly", 50]
]);
// → { moe: 30, larry: 40, curly: 50 }
Try It Yourself

How It Works

  1. One argument. Omit values — Underscore treats each inner array as a pair.
  2. Read pair[0]. That becomes the property name.
  3. Read pair[1]. That becomes the property value.
  4. Same shape. Result matches Example 1 — pick the form that fits your data.

Example 3 — Duplicate Keys (Last Wins)

A repeated key keeps only the final value written.

Underscore
_.object([["role", "user"], ["role", "admin"]]);
// → { role: "admin" }
Try It Yourself

How It Works

  1. First pair. Sets role to "user".
  2. Second pair. Same key again — overwrites with "admin".
  3. One property. Objects cannot hold two keys with the same name.
  4. Rule. Last write wins — plan for that when merging lists.

Example 4 — Header + Row → Record

Turn a CSV-style header and a data row into a labeled object.

Underscore
var header = ["id", "name", "active"];
var row = ["7", "Ava", "true"];

_.object(header, row);
// → { id: "7", name: "Ava", active: "true" }
Try It Yourself

How It Works

  1. Header = keys. Column names become property names.
  2. Row = values. Cells map by index to those keys.
  3. Lookup by name. You can read record.name instead of row[1].
  4. Types stay as given. Values are not auto-parsed — "true" stays a string.

Browser & Runtime Support

_.object 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

_.object()

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
_.object 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]). Native alternatives include Object.fromEntries(pairs) (ES2019) for the pairs form.

Frequently Asked Questions

_.object turns arrays into an object. Pass a list of [key, value] pairs, or a list of keys plus a matching list of values, and it returns { key: value, ... }.
_.object(pairs) with one array of [key, value] pairs, or _.object(keys, values) with two separate arrays.
The last value wins. Later entries overwrite earlier ones for the same key.
Yes. Plain object keys are strings, so numbers and other values used as keys are coerced to strings.
They are inverses. _.object builds an object from pairs (or keys and values). _.pairs turns an object into an array of [key, value] pairs.
No. It returns a new object and leaves the source arrays unchanged.

Next: _.chunk()

Split an array into fixed-size groups — great for pages, pairs, and grids.

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