Ramda.js R.nthArg() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

R.nthArg(n) returns a function which returns its nth argument (official Ramda docs). Indexes are zero-based, and negative numbers count from the end — handy for callbacks that receive several arguments when you only need one.

Stable since v0.9.0: R.nthArg is not deprecated, experimental, or non-standard. Watch out: the function it returns is curried, so positive indexes wait until enough arguments arrive.

Syntax

Call R.nthArg. Start with this line.

Ramda
R.nthArg(n)(...args)
CallWhat it does
R.nthArg(n)(...args)Primary signature.
R.nthArg(...)Call the function helper.

Prefer import { nthArg } from "ramda" when you want a named import.

Library declarations
Ramda
R.nthArg(n)(...args)

Parameters

ParameterDescription
nRequired. Integer position; 0–9, or negative from the end

Return Value

Return ValueDescription
*The argument at position n, or undefined if a negative index misses

Ramda Examples

Example 1 — Official Second and Last

Pick the second argument, then the last one — the samples from the Ramda docs.

Ramda
console.log(R.nthArg(1)('a', 'b', 'c'));  // "b"
console.log(R.nthArg(-1)('a', 'b', 'c')); // "c"
Try It Yourself

How It Works

  1. Build a picker. R.nthArg(1) returns a function that reads slot 1.
  2. Call it. Slots are 'a' = 0, 'b' = 1, 'c' = 2, so you get 'b'.
  3. Count from the end. -1 becomes 3 + (-1) = 2 → 'c'.
  4. Same idea as at(). Negative positions work like Array.at(-1), but on arguments.

Example 2 — Always Get the Last Argument

A negative picker adapts to however many arguments you pass.

Ramda
const last = R.nthArg(-1);

console.log(last(1, 2, 3));      // 3
console.log(last('only'));       // "only"
console.log(last(true, false));  // false
Try It Yourself

How It Works

  1. One picker. last is created once with -1.
  2. Three arguments. 3 + (-1) = 2 → slot 2 → 3.
  3. One argument. 1 + (-1) = 0 → slot 0 → 'only'.
  4. Two arguments. 2 + (-1) = 1 → false. The position is worked out on every call.

Example 3 — Collect Indexes with map

Native map calls the callback with (value, index, array); slot 1 is the index.

Ramda
const letters = ['a', 'b', 'c'];

console.log(letters.map(R.nthArg(1)));             // [0, 1, 2]
console.log(R.addIndex(R.map)(R.nthArg(1), letters)); // [0, 1, 2]
Try It Yourself

How It Works

  1. Native map. Array.prototype.map passes value, index, and array on each call.
  2. Pick slot 1. R.nthArg(1) keeps the index and drops the rest → [0, 1, 2].
  3. Ramda’s map. R.map passes only the value, so wrap it with R.addIndex to supply the index.
  4. Result. Both lines print the same index list.

Example 4 — Skip the First Argument in a Pipeline

Start a pipeline with R.nthArg(1) to ignore argument 0 and work on argument 1.

Ramda
const shoutSecond = R.pipe(R.nthArg(1), R.toUpper);

console.log(shoutSecond('ignored', 'ada')); // "ADA"
console.log(shoutSecond.length);            // 2
Try It Yourself

How It Works

  1. First step picks. R.nthArg(1) receives ('ignored', 'ada') and returns 'ada'.
  2. Next step transforms. R.toUpper turns 'ada' into 'ADA'.
  3. Arity carries over. R.pipe takes the first function’s arity, so shoutSecond.length is 2.
  4. Why it helps. No need to write (_, name) => name.toUpperCase().

Example 5 — Positive Indexes Wait for Enough Arguments

R.nthArg(1) needs two arguments before it can read slot 1.

Ramda
const second = R.nthArg(1);

console.log(typeof second('a'));   // "function"
console.log(second('a')('b'));     // "b"
console.log(second('a', 'b', 'c')); // "b"
Try It Yourself

How It Works

  1. Arity n + 1. To read slot 1, the picker is curried to 2 arguments.
  2. Too few. second('a') has one argument, so it returns a function that waits.
  3. Complete it. second('a')('b') now has two → 'b'.
  4. Extra is fine. second('a', 'b', 'c') has enough at once, so it runs → 'b'.

Browser & Runtime Support

R.nthArg() is plain JavaScript inside Ramda (available since v0.9.0). It uses no browser API, so support depends only on loading Ramda.

✓ Ramda 0.9.0+ · Any JS runtime

Ramda.js R.nthArg()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge. Via npm it works in Node.js, Deno, and Bun with require or import.

100% With Ramda loaded
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
R.nthArg() Universal

Bottom line: Safe in any project that includes Ramda. Load ramda.min.js from a CDN in the browser, or npm install ramda for Node, Deno, and Bun. These labs load [email protected] from jsDelivr.

Frequently Asked Questions

R.nthArg(n) returns a new function that, when called, returns its nth argument (zero-based). The official sample R.nthArg(1)('a', 'b', 'c') returns 'b'.
Yes. Negative n counts from the end of the arguments: R.nthArg(-1)('a', 'b', 'c') returns 'c', the last argument, no matter how many arguments are passed.
The returned function is curried to n + 1 arguments. To read slot 1 it needs at least two arguments, so with only one it waits and returns a function. R.nthArg(1)('a')('b') returns 'b'.
Ramda's map passes only the value to the callback, so nthArg(1) never receives an index and returns waiting functions. Use the native list.map(R.nthArg(1)) or R.addIndex(R.map) instead.
R.nth(n, list) reads an item from an array you already have. R.nthArg(n) builds a function that reads from its own call arguments, which is useful for callbacks that receive several arguments.
No. R.nthArg has been a stable Ramda function helper since v0.9.0. It is not deprecated, experimental, or non-standard.

Next: R.o()

Compose two unary functions, right to left, in one curried call.

R.o() 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.

6 people found this page helpful