Ramda.js R.path() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Ramda’s R.path() answers a nested question: what value sits at this trail of keys? You pass a path array, then the object (or array). You get the nested value, or undefined if any step is missing. Native JavaScript’s cousin is optional chaining: obj?.a?.b. That is data-first. path is data-last, so R.path(['user', 'name']) is already a function of one object — ready for R.map or R.pipe.

The official sample is the whole idea. R.path(['a', 'b'], {a: {b: 2}}) is 2. The same path on {c: {b: 2}} is undefined. Integers mix in for arrays: ['a', 'b', 0] reads the first item of a.b. Need one key? That is R.prop. Need one list index? That is R.nth. Need to know if the path exists? That is R.hasPath. Need a default? Next is R.pathOr. Need to write the path? That is R.assocPath.

Syntax

Call R.path. Start with this line.

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

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

Library declarations
Ramda
R.path(path, obj)

Parameters

ParameterDescription
pathRequired. Array. Keys to walk. Strings (and symbols) are object keys. Integers are array indexes, including negatives. An empty path returns obj itself.
objRequired. Object or Array. The source. null and undefined yield undefined. The source is never mutated.

Return Value

Return ValueDescription
Any or undefinedThe value at the tail of path, or undefined if any node is missing, null, or not indexable. A stored undefined looks the same as a miss.

Ramda Examples

📚 Getting Started

The official nested sample, then the same helper on an array inside an object.

Example 1 — Official Nested Path

A present trail returns the value. A missing first key returns undefined without throwing.

Ramda
R.path(['a', 'b'], {a: {b: 2}});
//=> 2

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

How It Works

Ramda walks a, then b. The second object has no a, so the walk stops. Native {c: {b: 2}}.a.b would throw. That is the docs sample from ramdajs.com.

Example 2 — Array Index in the Path

An integer segment means “this node is a list.” Index 0 is the first item of a.b.

Ramda
R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}});
//=> 1

R.path(['a', 'b', 2], {a: {b: [1, 2, 3]}});
//=> 3
Try It Yourself

How It Works

Path ['a', 'b', 0] means: key a, key b, then array index 0. Pass a number, not '0', so the walk uses R.nth instead of a string property name.

📈 Practical Patterns

Compare cousins, then negatives and integer object keys, then a curried helper and an empty path.

Example 3 — vs prop, nth, and hasPath

prop and nth are one-step cousins. hasPath tells existence. A stored undefined looks like a miss to path, but not to hasPath.

Ramda
const obj = {a: {b: 2}, list: [10, 20]};

R.path(['a'], obj);
//=> {b: 2}
R.prop('a', obj);
//=> {b: 2}

R.path(['list', 1], obj);
//=> 20
R.nth(1, obj.list);
//=> 20

const hole = {a: {b: undefined}};
R.path(['a', 'b'], hole);
//=> undefined
R.hasPath(['a', 'b'], hole);
//=> true
Try It Yourself

How It Works

path(['a'], obj) matches prop('a', obj). The list slot matches nth. hasPath still says b exists when its value is undefined. If you must tell a stored hole from a missing key, use R.hasPath, not path alone.

Example 4 — Negative Indexes and Integer Keys

Negatives count from the end of an array, through R.nth. An integer on a plain object still reads the coerced key. A negative on a non-list is unspecified leftover undefined.

Ramda
R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}});
//=> 2

R.path([2], {'2': 2});
//=> 2

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

How It Works

-2 on [1, 2, 3] is the second-to-last item, 2. nth(2, {'2': 2}) still finds key '2' because JavaScript coerces the index. nth(-2, {'-2': 'a'}) does not look up the string '-2' — the leftover is undefined. Those three calls are the rest of the docs sample.

Example 5 — Curry, Map, Empty Path, Dotted String

Fill the path to map over rows. An empty path returns the whole value. A dotted string is one literal key, not two.

Ramda
const userName = R.path(['user', 'name']);

R.map(userName, [
  { user: { name: 'Ada' } },
  { user: { name: 'Bo' } }
]);
//=> ['Ada', 'Bo']

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

R.path(['user.name'], { user: { name: 'Ada' } });
//=> undefined
Try It Yourself

How It Works

Because path is arity 2, filling the path leaves a function of one object. An empty array never walks, so you get the input back. ['user.name'] looks for a key whose name includes a dot. Split it: ['user', 'name']. Lodash _.get(obj, 'user.name') parses dots; Ramda does not.

Browser Support

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

✓ Ramda 0.2.0+ · Any JS runtime

Ramda.js R.path()

Load Ramda 0.2.0 or later via CDN or npm, then call R.path with a path array and an object. No extra browser API is required.

100% With Ramda 0.2.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.path() Universal

Bottom line: Safe in any project that includes Ramda 0.2.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.path(path, obj) walks a list of keys and returns the nested value. A missing segment, null, or undefined along the way yields undefined. Added in v0.2.0. Strings are object keys. Integers are array indexes (including negatives via R.nth).
R.path(['a', 'b'], {a: {b: 2}}) is 2. R.path(['a', 'b'], {c: {b: 2}}) is undefined. R.path(['a', 'b', 0], {a: {b: [1, 2, 3]}}) is 1. R.path(['a', 'b', -2], {a: {b: [1, 2, 3]}}) is 2.
prop reads one object key. nth reads one list index. path walks a path array that can mix both. hasPath asks whether the path exists as own keys; path returns the value, so undefined can mean missing or a stored undefined.
No. A missing key, a non-object mid-path, null, or undefined returns undefined. That is safer than obj.a.b, which throws when a is missing.
Use R.pathOr(default, path, obj). path itself has no default. R.propOr is the one-key cousin.
No. R.path is a stable Ramda object helper from v0.2.0. It is not deprecated, experimental, or non-standard.

Continue to R.pathOr()

Learn how to read a nested path with a default using Ramda R.pathOr().

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