Lodash _.unary() method

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

What you’ll learn

  • Why map passes three arguments and how unary hides extras.
  • How _.unary(parseInt) restores sane radix defaults.
  • How unary compares to _.ary(fn, 1).
  • When unary hurts debugging because indexes disappear.

Prerequisites

See _.ary(), _.throttle(), and the Function hub.

  • Array.prototype.map: callback signature (element, index, array).
  • parseInt radix: second parameter selects numeral base.

Overview

_.unary(func) wraps func so only the first invocation argument reaches the inner implementation—every extra parameter Lodash or native iterators supply is ignored.

Syntax

javascript
_.unary(func)
  • func: function whose arity should collapse to one.
  • returns: unary wrapper forwarding only the first argument.
1

Fix map(parseInt)

Without unary the numeric indices become accidental radix arguments.

javascript
import unary from "lodash/unary";

["10", "10", "10"].map(parseInt);
// [10, NaN, 2]

["10", "10", "10"].map(unary(parseInt));
// [10, 10, 10]
2

Ignore accidental iteratee metadata

When helper treats the second parameter as optional formatting, map indexes corrupt output unless unary trims arity.

javascript
import unary from "lodash/unary";

function label(word, emoji) {
  return emoji ? `${emoji} ${word}` : word;
}

["alert", "done"].map(label);
// ["alert", "1 done"] — index 1 is treated like emoji prefix

["alert", "done"].map(unary(label));
// ["alert", "done"]
3

Pair with lodash iterators

Lodash collection methods pass similar triples—unary keeps predicates focused on values.

javascript
import unary from "lodash/unary";
import map from "lodash/map";

const doubled = map(["2", "4", "8"], unary(Number));

doubled;
// [2, 4, 8]

📋 _.unary vs _.ary(func, 1) vs arrow wrappers

ApproachWhen to useNote
_.unaryReadable unary adaptersSame effect as ary(fn, 1)
_.ary(fn, 1)General arity capsUse higher n for other limits
(x) => fn(x)One-off lambdasNo lodash metadata helpers

Pitfalls to avoid

Indexes

Needing position-aware logic

Unary removes index access—reach for explicit lambdas when parity or offsets matter.

Methods

this-bound APIs

Do not expect unary to preserve method extraction semantics—bind first when internal code relies on receiver state.

Clarity

Obscure parses

Sometimes (v) => parseInt(v, 10) documents intent better than unary for newcomers.

❓ FAQ

A wrapper that forwards at most one argument to func—additional invocation parameters are discarded.
map passes (value, index, array). parseInt interprets the index as radix after the first element, producing NaN or odd parses.
They target the same arity cap; unary reads more clearly when you specifically want a unary callback.
No—wrapper forwards the invocation context unless you compose further with bind.
Use import unary from "lodash/unary" for tree-shaking friendly bundles.

Summary

Did you know?

Lodash documents _.unary as sugar for _.ary(func, 1)—the wrapper keeps arity predictable when third-party APIs forward extra parameters you never meant to consume.

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