Lodash _.overArgs() method

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

What you’ll learn

  • How _.overArgs adapts arguments position-by-position.
  • How unary transforms receive each slot and feed func.
  • How overArgs differs from _.flip, _.rearg, and manual spreads.
  • Pitfalls around sparse transform arrays and mismatched arity.

Prerequisites

Helpful reads: _.flip(), _.once(), and the Function hub.

  • Callbacks: functions passed as values or returned from helpers.
  • Unary functions: adapters that consume one input at a time.

Overview

_.overArgs(func, transforms) runs each argument through its paired transform (indexed like parameter positions), then executes func with the adapted values—ideal for quick coercion at API boundaries.

Syntax

javascript
_.overArgs(func, transforms)
  • func: target function receiving mapped arguments.
  • transforms: array of unary adapters aligned with parameter positions.
  • returns: wrapped invoker that applies transforms before delegating.
1

Coerce string inputs to numbers

Parse digits coming from form fields before doing arithmetic.

javascript
import overArgs from "lodash/overArgs";

const sum = overArgs(
  (a, b) => a + b,
  [(x) => parseInt(x, 10), (x) => parseInt(x, 10)]
);

sum("12", "30"); // 42
2

Merge JSON snippets through transforms

Turn pair-wise string payloads into objects before handing them to Object.assign.

javascript
import overArgs from "lodash/overArgs";

const mergeJsonStrings = overArgs(Object.assign, [
  JSON.parse,
  JSON.parse
]);

mergeJsonStrings('{"x":1}', '{"y":2}');
// { x: 1, y: 2 }
3

Normalize only selected slots

Use explicit passthrough transforms where you need identity behavior.

javascript
import overArgs from "lodash/overArgs";
import identity from "lodash/identity";

const labelSku = overArgs(
  (prefix, code) => `${prefix}-${code}`,
  [(s) => String(s).trim().toUpperCase(), identity]
);

labelSku(" sku ", "0042"); // "SKU-0042"

📋 _.overArgs vs manual wrappers vs _.wrap

ApproachStrengthTrade-off
_.overArgsDeclarative per-argument coercionYou must keep transforms aligned with arity
Manual wrapperFull control inside one blockRepeated boilerplate across projects
_.wrapInject a single outer value before funcNot positional transforms across many args

Pitfalls to avoid

Arity

Mismatch with transforms

Ensure every positional adapter you rely on exists or intentionally defaults via identity; sparse arrays are brittle.

Variadic

Extra trailing arguments

Transforms only cover declared indexes—unexpected extra args still reach func unchanged.

Errors

Throwing transforms

JSON.parse and friends throw on bad input; validate strings before piping them through adapters.

❓ FAQ

It returns a wrapper that maps each incoming argument through the transform at the same index (each transform is treated as unary), then calls func with those mapped values.
No. overArgs does not add or remove parameters—it only adapts values positionally before func executes.
flip reorders arguments as-is. overArgs lets you coerce or reshape each slot independently before func sees them.
Supply lodash identity (or an equivalent passthrough) for slots you do not want to change—avoid relying on sparse arrays.
Use import overArgs from "lodash/overArgs" for tree-shaking friendly bundles.

Summary

Did you know?

Lodash normalizes every entry in the transforms array with baseUnary, so each adapter receives exactly one value—the argument occupying the matching parameter slot—before func runs.

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