Lodash _.ary() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Creates a function that invokes func with up to n arguments, ignoring any additional ones. Part of Lodash 4.x Function (since 3.0.0).

Pass the required arguments shown below. Most helpers return a new function you call later.

Syntax

Call _.ary. Start with this line.

Lodash
_.ary(func, [n=func.length])
CallWhat it does
_.ary(func, [n=func.length])Primary signature.
_.ary(func)Wrap or transform a function.

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

Library declarations
Lodash
_.ary(func, [n=func.length])

Parameters

ParameterDescription
funcRequired. Function whose arguments you want to cap
nOptional. Max args to forward; defaults to func.length
guardOptional. When truthy, n is ignored (iteratee-safe composition)

Return Value

Return ValueDescription
*New capped function

Lodash Examples

Example 1 — Official map + parseInt

Forward only the string so index never becomes a radix.

Lodash
_.map(["6", "8", "10"], _.ary(parseInt, 1));
// → [6, 8, 10]
Try It Yourself

How It Works

  1. Wrap. _.ary(parseInt, 1) keeps only the first argument.
  2. Map. Lodash still calls the iteratee with value, index, array.
  3. Drop. Index and array never reach parseInt.
  4. Result. Clean decimal parses — same as the official docs.

Example 2 — Broken Without ary

Passing bare parseInt lets the index act as radix.

Lodash
_.map(["6", "8", "10"], parseInt);
// → [6, NaN, 2]
Try It Yourself

How It Works

  1. Call shape. Iteratee gets (value, index, array).
  2. Radix. parseInt’s second parameter is the radix.
  3. Index 1. Invalid radix → NaN for "8".
  4. Index 2. Binary parse of "10" → 2.

Example 3 — Cap at Two Arguments

Keep the first two args; drop anything after.

Lodash
function join3(a, b, c) {
  return [a, b, c].join("-");
}

var take2 = _.ary(join3, 2);

take2("x", "y", "z");
// → "x-y-"   // c is undefined
Try It Yourself

How It Works

  1. Cap. n = 2 means only a and b are forwarded.
  2. Drop. "z" never reaches join3.
  3. Missing. Parameter c stays undefined.
  4. Use. Handy when a helper accepts more params than a caller should pass.

Example 4 — Default n = func.length

Omit n to cap at the function’s declared arity.

Lodash
function add(a, b) {
  return a + b;
}

var capped = _.ary(add); // n → 2

capped(2, 3, 99);
// → 5
Try It Yourself

How It Works

  1. Length. add.length is 2.
  2. Default. Nullish n → Lodash uses that length.
  3. Call. Extra 99 is ignored; 2 + 3 remains.
  4. Note. Rest params / defaults can make .length surprising — set n explicitly when unsure.

Example 5 — ary(…, 1) vs unary

Same job; pick the name that reads clearer.

Lodash
var a = _.map(["6", "8", "10"], _.ary(parseInt, 1));
var b = _.map(["6", "8", "10"], _.unary(parseInt));

a; // → [6, 8, 10]
b; // → [6, 8, 10]
Try It Yourself

How It Works

  1. unary. Always caps at one argument.
  2. ary. Caps at any n; 1 matches unary.
  3. Source. Lodash implements unary as ary(func, 1).
  4. Style. Prefer unary for one-arg intent; ary when n varies.

Browser & Runtime Support

_.ary is a Lodash 4.x Function helper (since 3.0.0). It needs no special browser APIs beyond loading Lodash.

✓ Stable · Lodash 3.0.0+

_.ary()

Available in [email protected] full builds and the lodash/ary modular import. Works in evergreen browsers and Node / Bun / Deno when Lodash is installed.

100% With Lodash 4.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
_.ary Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import ary from "lodash/ary" for smaller builds.

Frequently Asked Questions

_.ary(func, [n]) returns a new function that invokes func with up to n arguments and ignores any extras. If n is omitted, Lodash uses func.length.
map calls the iteratee as (value, index, array). parseInt treats the second argument as radix, so indexes corrupt later parses. _.ary(parseInt, 1) forwards only the string.
unary hard-codes one argument. ary lets you pick any n. _.unary(fn) matches _.ary(fn, 1).
When truthy (as when Lodash passes iteratee extras), n is ignored and Lodash falls back to func.length so ary composes safely as an iteratee.
The capped wrapper still invokes func with the caller's this (unless you bind separately). It mainly strips extra arguments.
Use import ary from "lodash/ary" or require("lodash/ary") for tree-shaking. Full build: import _ from "lodash" then _.ary.

Next: _.before()

Invoke a function only for the first n−1 calls, then freeze on the last result.

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