Ramda.js R.addIndexRight() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Like R.addIndex, it wraps a list iterator so the callback receives index and list. The difference: the index starts at list.length - 1 and counts down to 0.

Stable: R.addIndexRight has been in Ramda since v0.29.0. It is not deprecated, experimental, or non-standard. Prefer R.addIndex when you want indexes starting at 0 from the left.

Syntax

Call R.addIndexRight. Start with this line.

Ramda
R.addIndexRight(fn)
CallWhat it does
R.addIndexRight(fn)Primary signature.
R.addIndexRight(...)Call the function helper.

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

Library declarations
Ramda
R.addIndexRight(fn)

Parameters

ParameterDescription
fnRequired. Iterator to wrap (e.g. R.map or a custom revmap)
CallbackRequired. Gets original args + descending index + list
ListRequired. Last argument of the wrapped iterator

Return Value

Return ValueDescription
*New curried iterator (original unchanged)

Ramda Examples

Example 1 — Official revmapIndexed

Reverse the list, then attach indexes from the right.

Ramda
const revmap = (fn, ary) => R.map(fn, R.reverse(ary));
const revmapIndexed = R.addIndexRight(revmap);

console.log(
  revmapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r'])
);
// → ['5-r', '4-a', '3-b', '2-o', '1-o', '0-f']
Try It Yourself

How It Works

  1. Reverse. R.reverse turns the letters into r, a, b, o, o, f.
  2. Wrap. R.addIndexRight(revmap) starts the index at 5.
  3. Label. First visit is 'r' with idx 5 → '5-r'.
  4. Countdown. Indexes fall to 0 on the final visit ('f').

Example 2 — R.addIndex vs R.addIndexRight

Without reversing, both still visit f first — only the numbers change.

Ramda
const list = ['f', 'o', 'o', 'b', 'a', 'r'];
const label = (val, idx) => idx + '-' + val;

console.log(R.addIndex(R.map)(label, list));
// → ['0-f', '1-o', '2-o', '3-b', '4-a', '5-r']

console.log(R.addIndexRight(R.map)(label, list));
// → ['5-f', '4-o', '3-o', '2-b', '1-a', '0-r']
Try It Yourself

How It Works

  1. Same visit order. R.map still walks left to right.
  2. Left wrap. R.addIndex labels 'f' as 0.
  3. Right wrap. R.addIndexRight labels 'f' as 5.
  4. Want 'r' first? Keep the official revmap helper from Example 1.

Example 3 — Filter High Indexes

Keep items whose attached index is 3 or more — left-count and right-count pick opposite ends.

Ramda
const letters = ['a', 'b', 'c', 'd', 'e'];
const keepHigh = (val, idx) => idx >= 3;

console.log(R.addIndex(R.filter)(keepHigh, letters));
// → ['d', 'e']          // indexes 0,1,2,3,4

console.log(R.addIndexRight(R.filter)(keepHigh, letters));
// → ['a', 'b']          // indexes 4,3,2,1,0
Try It Yourself

How It Works

  1. Same predicate. idx >= 3 on both wrappers.
  2. Left indexes. High numbers sit at the end → keep 'd', 'e'.
  3. Right indexes. High numbers sit at the start → keep 'a', 'b'.
  4. Order. Filter still walks left to right, so kept letters stay in original order.

Example 4 — Reduce with a Countdown Index

After wrapping, the iteratee is (acc, value, index, list) with index counting down.

Ramda
const reduceIndexedRight = R.addIndexRight(R.reduce);

console.log(
  reduceIndexedRight(
    (acc, val, idx) => acc.concat(idx + ':' + val),
    [],
    ['a', 'b', 'c']
  )
);
// → ['2:a', '1:b', '0:c']
Try It Yourself

How It Works

  1. Fold left. R.reduce still visits a, then b, then c.
  2. Start high. First step gets idx 2 → '2:a'.
  3. Countdown. Next steps append '1:b' and '0:c'.
  4. Compare. R.addIndex(R.reduce) would build ['0:a', '1:b', '2:c'].

Example 5 — Which Item Is idx === 0?

On a left-to-right map, countdown 0 lands on the last item — not the first.

Ramda
const items = ['alpha', 'beta', 'gamma'];
const markZero = (val, idx) => idx === 0 ? val + ' (idx 0)' : val;

console.log(R.addIndex(R.map)(markZero, items));
// → ['alpha (idx 0)', 'beta', 'gamma']

console.log(R.addIndexRight(R.map)(markZero, items));
// → ['alpha', 'beta', 'gamma (idx 0)']
Try It Yourself

How It Works

  1. Left wrap. idx === 0 is the first visit → 'alpha'.
  2. Right wrap. Countdown hits 0 on the last visit → 'gamma'.
  3. Gotcha. Do not copy a “mark first item” snippet onto R.addIndexRight.
  4. Fix. Use R.addIndex for the first item, or check idx === list.length - 1 with this wrapper.

Browser & Runtime Support

R.addIndexRight is a Ramda Function helper since v0.29.0. It is plain JavaScript — no special browser API. It runs anywhere Ramda 0.29+ loads (CDN, npm, bundler).

✓ Stable · Ramda 0.29.0+

R.addIndexRight()

Available in [email protected]+ full builds. Works in evergreen browsers and current Node LTS / Bun / Deno when Ramda is installed.

100% With Ramda 0.29+
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.addIndexRight Ramda 0.29.0+

Bottom line: Safe for production once Ramda 0.29.0+ is loaded. Use a CDN build such as ramda.min.js in the browser, or npm install ramda for Node. Projects stuck on older Ramda can keep using R.addIndex (v0.15.0+) for left-to-right indexes.

Frequently Asked Questions

R.addIndexRight(fn) wraps a list iterator such as R.map, R.filter, or R.reduce so the callback also receives the current index and the whole list. Unlike R.addIndex, the index starts at list.length - 1 and counts down.
const revmap = (fn, ary) => R.map(fn, R.reverse(ary)); const revmapIndexed = R.addIndexRight(revmap); then revmapIndexed((val, idx) => idx + '-' + val, ['f', 'o', 'o', 'b', 'a', 'r']) returns ['5-r', '4-a', '3-b', '2-o', '1-o', '0-f']. Added in v0.29.0.
Both add (value, index, list) to the callback. R.addIndex counts 0, 1, 2 from the left. R.addIndexRight counts length-1, length-2, … down to 0. The wrapped iterator still decides visit order — R.map still walks left to right unless you reverse first.
R.reverse plus R.addIndexRight visits the last letter first and gives it the last original index. That is how 'r' becomes '5-r' at the front of the result. Wrapping R.map alone would still output 'f' first, just with a high index.
Not with R.addIndexRight(R.map). Index 0 is attached to the last visit of a left-to-right map, which is the last item. With R.addIndex, idx === 0 is the first item.
No. R.addIndexRight is a stable Ramda Function helper from v0.29.0. It is not deprecated, experimental, or non-standard.

About the author

Next: R.always()

Create a function that always returns the same value, no matter the arguments.

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

12 people found this page helpful