Ramda.js R.reverse() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
List

Definition

R.reverse(list) returns a new array, or a new string, with the items in the opposite order. It is the safe, immutable version of native Array.prototype.reverse, and it works on strings too (official Ramda docs).

Stable since v0.1.0: R.reverse is not deprecated, experimental, or non-standard. Unlike native array.reverse(), it never changes the original array.

Syntax

Call R.reverse. Start with this line.

Ramda
R.reverse(list)
CallWhat it does
R.reverse(list)Primary signature.
R.reverse(...)Call the list helper.

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

Library declarations
Ramda
R.reverse(list)

Parameters

ParameterDescription
listRequired. An array, array-like, or string to reverse

Return Value

Return ValueDescription
*A new array in reverse order, or a new string for string input

Ramda Examples

Example 1 — Official: Reverse Arrays

The array samples from the Ramda docs, from three items down to none.

Ramda
console.log(R.reverse([1, 2, 3]));  // [3, 2, 1]
console.log(R.reverse([1, 2]));     // [2, 1]
console.log(R.reverse([1]));        // [1]
console.log(R.reverse([]));         // []
Try It Yourself

How It Works

  1. Three items. The last item becomes first: [3, 2, 1].
  2. Two items. The pair simply swaps places.
  3. One or zero. There is nothing to swap, so the result looks the same.
  4. Always new. Even [1] and [] come back as new arrays, not the originals.

Example 2 — Official: Reverse Strings

Pass a string and you get a string back, not an array.

Ramda
console.log(R.reverse('abc'));  // 'cba'
console.log(R.reverse('ab'));   // 'ba'
console.log(R.reverse('a'));    // 'a'
console.log(R.reverse(''));     // ''
Try It Yourself

How It Works

  1. Split. 'abc' is broken into ['a', 'b', 'c'].
  2. Reverse. The characters become ['c', 'b', 'a'].
  3. Join. They are glued back into the string 'cba'.
  4. Empty is fine. '' returns ''; the quotes in the output show it is an empty string.

Example 3 — Original Untouched vs Native reverse()

See the key difference from the built-in method.

Ramda
const nums = [1, 2, 3];
console.log(R.reverse(nums));  // [3, 2, 1]
console.log(nums);             // [1, 2, 3]

const other = [1, 2, 3];
other.reverse();
console.log(other);            // [3, 2, 1]
Try It Yourself

How It Works

  1. Ramda copies. R.reverse(nums) returns a reversed copy.
  2. Original safe. Printing nums afterwards still shows [1, 2, 3].
  3. Native mutates. other.reverse() flips other itself.
  4. Why it matters. If other was shared with other code, that code now sees a reversed list too.

Example 4 — Check for a Palindrome

A value is a palindrome when it equals its own reverse.

Ramda
const isPalindrome = (x) => R.equals(x, R.reverse(x));

console.log(isPalindrome('level'));    // true
console.log(isPalindrome('hello'));    // false
console.log(isPalindrome([1, 2, 1]));  // true
Try It Yourself

How It Works

  1. Reverse. R.reverse('level') is 'level' again.
  2. Compare. R.equals checks that both values match, so the answer is true.
  3. Not a match. 'hello' reversed is 'olleh', so the answer is false.
  4. Arrays too. R.equals compares arrays by content, so [1, 2, 1] also passes.

Example 5 — Use It in a Pipeline

R.reverse takes one argument, so it drops straight into R.pipe.

Ramda
const latestFirst = R.pipe(R.takeLast(3), R.reverse);
console.log(latestFirst(['Jan', 'Feb', 'Mar', 'Apr', 'May']));
// ['May', 'Apr', 'Mar']

const reverseWords = R.pipe(R.split(' '), R.reverse, R.join(' '));
console.log(reverseWords('one two three'));
// three two one
Try It Yourself

How It Works

  1. Take the end. R.takeLast(3) keeps ['Mar', 'Apr', 'May'].
  2. Newest first. R.reverse flips them to ['May', 'Apr', 'Mar'].
  3. Words, not letters. R.split(' ') makes an array of words, so R.reverse flips the word order.
  4. Back to text. R.join(' ') rebuilds the sentence: three two one.

Browser & Runtime Support

R.reverse() is plain JavaScript inside Ramda 0.1.0+: it copies the list and reverses the copy. Without Ramda, native Array.prototype.toReversed() (ES2023) also returns a reversed copy, but only in Chrome 110+, Firefox 115+, Safari 16+, and Node 20+.

✓ Ramda 0.1.0+ · Any JS runtime

Ramda.js R.reverse()

The UMD build (ramda.min.js) is compiled to ES5 syntax, so it runs in Chrome, Firefox, Safari, and Edge, including older versions without toReversed. Via npm it works in Node.js, Deno, and Bun.

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.reverse() Universal

Bottom line: Safe in any project with Ramda (check with npm ls 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].

Frequently Asked Questions

R.reverse(list) returns a new array or string with the items in the opposite order. The official samples: R.reverse([1, 2, 3]) returns [3, 2, 1] and R.reverse('abc') returns 'cba'.
No. It copies the list first and reverses the copy. Native Array.prototype.reverse changes the array in place, which can cause bugs when other code shares that array.
Yes. When you pass a string, you get a string back: R.reverse('abc') is 'cba'. It splits the string into UTF-16 code units, so emoji and some accented letters can break. Use Array.from(str).reverse().join('') for those.
No. It only reverses the top level. R.reverse([[1, 2], [3, 4]]) returns [[3, 4], [1, 2]], and the inner arrays keep their order. They are also the same references as before.
You can sort ascending and then reverse: R.pipe(R.sort((a, b) => a - b), R.reverse). A single R.sort(R.descend(R.identity), list) does it in one step and reads more clearly.
No. R.reverse has been a stable Ramda list function since v0.1.0. It is not deprecated, experimental, or non-standard.

Next: R.scan()

Like reduce, but returns every running total.

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