Ramda.js R.mapObjIndexed() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.mapObjIndexed() answers an object-map question: how do I transform every own value when I also need its key? You pass a function of (value, key, obj), then an object. You get a new object with the same keys and new values. The original is not mutated.

The official sample is the whole idea. {x: 1, y: 2, z: 3} becomes {x: 'x2', y: 'y4', z: 'z6'} because the callback prefixes the key and doubles the number. Need only the value? That is R.map. Need side effects and the same object back? That is R.forEachObjIndexed. Need new key names? That is the previous helper, R.mapKeys.

Syntax

Call R.mapObjIndexed. Start with this line.

Ramda
R.mapObjIndexed(fn, obj)
CallWhat it does
R.mapObjIndexed(fn, obj)Primary signature.
R.mapObjIndexed(...)Call the object helper.

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

Library declarations
Ramda
R.mapObjIndexed(fn, obj)

Parameters

ParameterDescription
fnRequired. Function. Called as fn(value, key, obj) for each own key. The return value becomes the new field.
objRequired. Object. The record to map. Own enumerable string keys only. Prototype names are skipped.

Return Value

Return ValueDescription
ObjectA new object with the same own keys and mapped values. The source object is not mutated.

Ramda Examples

📚 Getting Started

The official key-plus-double sample, then the same numbers with map that cannot see the key.

Example 1 — Official xyz

Prefix the key, double the number. Keys stay x, y, and z.

Ramda
const xyz = { x: 1, y: 2, z: 3 };
const prependKeyAndDouble = (num, key, obj) => key + (num * 2);
R.mapObjIndexed(prependKeyAndDouble, xyz);
//=> { x: 'x2', y: 'y4', z: 'z6' }
Try It Yourself

How It Works

obj is unused in this sample, but the signature still passes it. That is the docs example from ramdajs.com.

Example 2 — vs R.map

map doubles numbers. mapObjIndexed can glue the key onto that doubled number.

Ramda
const xyz = { x: 1, y: 2, z: 3 };

R.map((num) => num * 2, xyz);
//=> { x: 2, y: 4, z: 6 }
R.mapObjIndexed((num, key) => key + (num * 2), xyz);
//=> { x: 'x2', y: 'y4', z: 'z6' }
Try It Yourself

How It Works

If you never mention key in the callback, switch to R.map. That is what the docs recommend.

📈 Practical Patterns

A new object vs a side-effect walk, a share-of-total using the third argument, then a curried helper in a pipe.

Example 3 — vs R.forEachObjIndexed

mapObjIndexed returns a new object. forEachObjIndexed returns the original.

Ramda
const xyz = { x: 1, y: 2 };
const mapped = R.mapObjIndexed((num) => num * 2, xyz);
const walked = R.forEachObjIndexed(() => {}, xyz);

mapped;
//=> { x: 2, y: 4 }
walked === xyz;
//=> true
xyz;
//=> { x: 1, y: 2 }
Try It Yourself

How It Works

Same callback shape, different job. Map to transform. forEach to log or count. The source values stay 1 and 2.

Example 4 — Share of Total

The third argument is the whole object, so each score can be divided by the sum.

Ramda
const scores = { math: 80, art: 20 };
R.mapObjIndexed((num, key, obj) => num / R.sum(R.values(obj)), scores);
//=> { math: 0.8, art: 0.2 }
scores;
//=> { math: 80, art: 20 }
Try It Yourself

How It Works

key is unused here; obj is the reason to pick mapObjIndexed over map. You could also compute the total once outside the map for a slightly cheaper pass.

Example 5 — Curry with pipe

Label each value with its key, then list the labels. Both helpers are data-last.

Ramda
const label = R.mapObjIndexed((num, key) => key + ':' + num);
const labelValues = R.pipe(
  R.mapObjIndexed((num, key) => key + ':' + num),
  R.values
);
const xyz = { x: 1, y: 2 };

label(xyz);
//=> { x: 'x:1', y: 'y:2' }
labelValues(xyz);
//=> ['x:1', 'y:2']
Try It Yourself

How It Works

R.mapObjIndexed(fn) waits for the object. Drop it at the start of R.pipe when a later step needs the mapped values.

Browser Support

R.mapObjIndexed() is ordinary JavaScript once Ramda is loaded. Logos use the shared browser-image-sprite.png sprite from this project.

✓ Ramda 0.9.0+ · Any JS runtime

Ramda.js R.mapObjIndexed()

Load Ramda 0.9.0 or later via CDN or npm, then call R.mapObjIndexed with a callback and an object. No extra browser API is required.

100% With Ramda 0.9.0+
Google Chrome All versions · Desktop & Mobile
Full support
Mozilla Firefox All versions · Desktop & Mobile
Full support
Apple Safari All versions · macOS & iOS
Full support
Microsoft Edge All versions · Chromium & Legacy
Full support
Internet Explorer IE 6+ · Legacy environments
Full support
Opera All modern versions
Full support
R.mapObjIndexed() Universal

Bottom line: Safe in any project that includes Ramda 0.9.0 or later. Use a CDN build such as ramda.min.js in the browser or install ramda from npm for Node. These labs use [email protected].

Frequently Asked Questions

R.mapObjIndexed(fn, obj) returns a new object with the same own keys. Each value is fn(value, key, obj). Added in v0.9.0. The original object is not mutated.
const xyz = { x: 1, y: 2, z: 3 }. prependKeyAndDouble is (num, key, obj) => key + (num * 2). R.mapObjIndexed(prependKeyAndDouble, xyz) is { x: 'x2', y: 'y4', z: 'z6' }.
R.map only passes the value. Use map when the key does not matter. mapObjIndexed passes value, key, and the whole object. The docs say: if only the value is significant, use map instead.
forEachObjIndexed is for side effects and returns the original object. mapObjIndexed builds a new object of mapped values. mapKeys rewrites key names and copies values.
No. It walks R.keys(obj), so only own enumerable string keys. Inherited names and symbol keys are skipped.
No. R.mapObjIndexed is a stable Ramda object helper from v0.9.0. It is not deprecated, experimental, or non-standard.

Continue to R.mergeAll()

Learn how to fold a list of objects into one using Ramda R.mergeAll().

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