Lodash _.nthArg() Method

Beginner
5 min read
Updated: Nov 2026
4 examples
Util

Definition

Creates a function that returns the argument at index n. Negative n counts from the end (−1 is last). Part of Lodash Util since 3.7.0 (stable — not deprecated).

Pass the arguments shown below. Prefer modular imports when you only need this helper.

Syntax

Call _.nthArg. Start with this line.

Lodash
_.nthArg([n=0])
CallWhat it does
_.nthArg([n=0])Primary signature.
_.nthArg(...)Call the util helper.

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

Library declarations
Lodash
_.nthArg([n=0])

Parameters

ParameterDescription
nOptional. Index to return (default 0); negative counts from end

Return Value

Return ValueDescription
*A new function that returns args[n]

Lodash Examples

Example 1 — Official: Second Argument

Pick index 1 from ('a', 'b', 'c', 'd').

Lodash
var func = _.nthArg(1);

func('a', 'b', 'c', 'd');
// → 'b'
Try It Yourself

How It Works

  1. Build. _.nthArg(1) returns a picker for index 1.
  2. Call. Pass four arguments: a b c d.
  3. Pick. Slot 1 is 'b'.
  4. Reuse. Call func again with other args anytime.

Example 2 — Official: Negative Index

Count from the end — -2 is second-to-last.

Lodash
var func = _.nthArg(-2);

func('a', 'b', 'c', 'd');
// → 'c'
Try It Yourself

How It Works

  1. Negative. -2 means two steps from the end.
  2. Resolve. Length 4 + (-2) → index 2.
  3. Value. args[2] is 'c'.
  4. Last item. Use _.nthArg(-1) for the final argument.

Example 3 — Default Index 0

Omit n to pick the first argument.

Lodash
var first = _.nthArg();

first('a', 'b', 'c', 'd');
// → 'a'
Try It Yourself

How It Works

  1. Default. Missing n becomes 0.
  2. Same as. _.nthArg(0).
  3. Result. First argument 'a'.
  4. Note. Close to _.identity for a single arg — different when many args arrive.

Example 4 — Out-of-Range Index

A missing slot returns undefined — no error.

Lodash
var func = _.nthArg(5);

func('a', 'b');
// → undefined
Try It Yourself

How It Works

  1. Ask for 5. Only two arguments exist.
  2. Lookup. args[5] is missing.
  3. Return. undefined — never throws.
  4. Guard. Check the result if a missing arg is an error in your app.

Browser & Runtime Support

_.nthArg is a Lodash Util helper since 3.7.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 3.7.0+

_.nthArg()

Available in [email protected] full builds and the lodash/nthArg modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 3.7+
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
_.nthArg Lodash 3.7.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import nthArg from "lodash/nthArg" for smaller bundles.

Frequently Asked Questions

_.nthArg(n) returns a new function. When you call that function with any arguments, it returns only the argument at index n — 0 for first, 1 for second, and so on.
Yes. _.nthArg(-1) returns the last argument, _.nthArg(-2) the second-to-last — same idea as counting from the end of an array.
If you omit n, Lodash uses 0. _.nthArg() is the same as _.nthArg(0) and picks the first argument.
You get undefined. _.nthArg(2)('a', 'b') returns undefined because there is no third argument.
When an API wants a unary function but data arrives as multiple arguments — pick the one you need. Useful with _.over, _.flow, or other higher-order helpers.
No. It is a stable Lodash Util method since 3.7.0.

Next: _.over()

Invoke several iteratees with the same arguments and collect results.

_.over() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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