Ramda.js R.paths() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.paths() answers several nested questions at once: what values sit at these trails? You pass an array of path arrays, then the object. You get a list of leftovers in the same order. Native JavaScript would repeat optional chaining: [obj?.a?.b, obj?.p?.[0]?.q]. That is data-first. paths is data-last, so R.paths([['user', 'name'], ['user', 'id']]) is already a function of one object — ready for R.map or R.pipe.

The official sample is the whole idea. R.paths([['a', 'b'], ['p', 0, 'q']], {a: {b: 2}, p: [{q: 3}]}) is [2, 3]. Swap the second trail for ['p', 'r'] and the leftover is [2, undefined]. Need one trail? That is R.path. Need a default on one trail? That is R.pathOr. Need several top-level keys only? That is R.props.

Syntax

Call R.paths. Start with this line.

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

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

Library declarations
Ramda
R.paths(pathsArray, obj)

Parameters

ParameterDescription
pathsArrayRequired. Array of arrays. Each inner array is a path for R.path. An empty outer list returns []. An empty inner path returns obj in that slot.
objRequired. Object or Array. The source shared by every trail. null and undefined yield undefined in every slot that walks. The source is never mutated.

Return Value

Return ValueDescription
ArrayOne leftover per inner path, in order. A missing node or stored undefined is undefined in that slot. Length matches pathsArray.length.

Ramda Examples

📚 Getting Started

The official two-trail sample, then the same helper with extra array indexes.

Example 1 — Official Two Nested Paths

Both trails hit. Then the second trail misses and that slot is undefined.

Ramda
const obj = {a: {b: 2}, p: [{q: 3}]};

R.paths([['a', 'b'], ['p', 0, 'q']], obj);
//=> [2, 3]

R.paths([['a', 'b'], ['p', 'r']], obj);
//=> [2, undefined]
Try It Yourself

How It Works

The first inner path walks a then b. The second walks p, index 0, then q. p has no key r, so only that slot is empty. Native obj.p.r would throw. That is the docs sample from ramdajs.com.

Example 2 — Array Indexes and Negatives

Each inner path can mix object keys and list indexes, including negatives through R.nth.

Ramda
const tree = {a: {b: [1, 2, 3]}};

R.paths([['a', 'b', 0], ['a', 'b', -1]], tree);
//=> [1, 3]

R.paths([['a', 'b', 9]], tree);
//=> [undefined]
Try It Yourself

How It Works

Index 0 is the first item. -1 is the last. Index 9 is off the list, so that one-item leftover is [undefined]. Pass numbers, not '0', so the walk uses nth.

📈 Practical Patterns

Compare cousins, then a curried helper, then empty lists and dotted-string pitfalls.

Example 3 — vs path and props

path unwraps one leftover. paths keeps the array. props only reads top-level keys.

Ramda
const obj = {a: {b: 2}, p: [{q: 3}]};

R.paths([['a', 'b']], obj);
//=> [2]
R.path(['a', 'b'], obj);
//=> 2

R.props(['a', 'p'], obj);
//=> [{b: 2}, [{q: 3}]]

R.paths([['a'], ['p', 0, 'q']], obj);
//=> [{b: 2}, 3]
Try It Yourself

How It Works

paths([['a', 'b']], obj) is [R.path(['a', 'b'], obj)]. props cannot reach p[0].q; it only looks at own top-level names. Mix one-segment and nested trails in the same pathsArray when you need both.

Example 4 — Curry and Map

Fill the path list to map over rows. A missing y leaves undefined in that pair.

Ramda
const xy = R.paths([['x'], ['y']]);

R.map(xy, [
  { x: 1, y: 2 },
  { x: 3 }
]);
//=> [[1, 2], [3, undefined]]
Try It Yourself

How It Works

Because paths is arity 2, filling the path list leaves a function of one object. Each row becomes a two-item leftover. For a named fallback, map R.pathOr instead, or run R.map(R.defaultTo(0), pair) after the fact.

Example 5 — Empty Paths, Dotted String, Stored Undefined

An empty outer list is []. An empty inner path returns the object. A dotted string is one literal key. A stored undefined looks like a miss.

Ramda
R.paths([], {a: 1});
//=> []

R.paths([[]], {a: 1});
//=> [{a: 1}]

R.paths([['user.name']], { user: { name: 'Ada' } });
//=> [undefined]

R.paths([['a', 'b']], {a: {b: undefined}});
//=> [undefined]
Try It Yourself

How It Works

No inner paths means no leftovers. An empty inner array never walks, so you get the input back in that slot. ['user.name'] looks for a key whose name includes a dot. Split it: ['user', 'name']. Use R.hasPath when a stored hole must count as present.

Browser Support

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

✓ Ramda 0.27.1+ · Any JS runtime

Ramda.js R.paths()

Load Ramda 0.27.1 or later via CDN or npm, then call R.paths with a list of path arrays and an object. No extra browser API is required.

100% With Ramda 0.27.1+
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.paths() Universal

Bottom line: Safe in any project that includes Ramda 0.27.1 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.paths(pathsArray, obj) walks every inner path and returns a list of leftovers in the same order. A miss is undefined in that slot. Added in v0.27.1.
R.paths([['a', 'b'], ['p', 0, 'q']], {a: {b: 2}, p: [{q: 3}]}) is [2, 3]. The same object with ['p', 'r'] in the second path is [2, undefined].
path walks one trail and returns one value. paths walks many trails and always returns an array. props reads several top-level keys only; each name is one key, not a nested path.
No. A missing segment, null, or undefined along a trail puts undefined in that slot. Other trails still run. Native obj.a.b would throw.
paths itself has no default. Map pathOr, or map defaultTo over the leftover list. R.pathOr(d, path, obj) is the one-trail cousin with a fallback.
No. R.paths is a stable Ramda object helper from v0.27.1. It is not deprecated, experimental, or non-standard.

Continue to R.pick()

Learn how to keep a list of keys on a partial copy using Ramda R.pick().

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