Lodash _.reverse() method

Beginner
⏱️ 6 min read
📚 Updated: May 2026
🎯 3 Code examples
🚀 3 Try-it labs
Lodash

What you’ll learn

  • How _.reverse(array) mirrors Array.prototype.reverse while fitting Lodash’s array-like handling.
  • Why the method mutates and still returns the same reference.
  • Patterns for an immutable reversed view without surprising collaborators.
  • Try each example in the editor (?tryit=1, 2, 3) with Lodash from a CDN.

Prerequisites

Skim _.remove() or _.pull() if you are still building intuition around Lodash mutators versus immutable helpers.

  • You know that reversing changes indexes for every element except the middle slot on odd lengths.
  • You can run snippets in Node or open the Try-it labs in a browser.

Overview

_.reverse exists so reversing stays ergonomic inside Lodash pipelines and consistent across array-like inputs: mutate the sequence, return the same reference, and keep chaining fluent.

In place

The collection you pass is the one whose order changes—plan snapshots before calling when undo stacks matter.

Symmetric swap

First meets last, inward until the middle—no allocation for the reversal itself.

Chain friendly

Returning the original reference lets you continue with other Lodash mutators without juggling temporaries.

Syntax

javascript
_.reverse(array)
  • array: collection to reverse (array-like values are coerced).
  • Returns: the same array reference after its elements are reversed.
1

Reverse values

Call reverse once and the original binding reflects the flipped order immediately.

javascript
import reverse from "lodash/reverse";

const nums = [1, 2, 3];
reverse(nums);
// nums is now [3, 2, 1]
Try it Yourself
2

Same reference

The return value aliases the input—handy for chaining, risky if you expected a forked array.

javascript
import reverse from "lodash/reverse";

const xs = ["a", "b", "c"];
const out = reverse(xs);
// out === xs  →  true
Try it Yourself
3

Keep the original order

Clone shallowly, reverse the clone, and leave upstream consumers untouched.

javascript
import reverse from "lodash/reverse";

const original = [10, 20, 30];
const mirror = reverse(original.slice());
// original → [10, 20, 30]; mirror → [30, 20, 10]
Try it Yourself

📋 _.reverse vs native vs non-mutating copies

APIMutates input?Returns
_.reverse(array)YesSame array reference, reversed
array.reverse()YesSame array reference (native)
[...array].reverse()No (copies first)New array reversed; original untouched
array.slice().reverse()NoNew array reversed; original untouched

Pitfalls to avoid

Share

Hidden aliasing

Exported constants or cached arrays reverse for every importer—clone when ownership should stay local.

Undo

Expecting immutability

Histories and Redux-style reducers usually forbid this mutation; copy then reverse or use pure helpers instead.

UI

Accidental re-render churn

Frameworks that detect reference equality may miss in-place reversals—pair with intentional state updates.

❓ FAQ

Yes. Elements are swapped in place so every observer of that reference sees the new order immediately.
The same collection reference after reversing—useful for chaining Lodash calls without an extra assignment.
Spread (or slice) builds a shallow copy; reversing that copy leaves the original array untouched. _.reverse targets the original storage.
Lodash normalizes array-like values so long as length and numeric indexes behave like an array; dense sequences behave predictably.
Use import reverse from "lodash/reverse" or require("lodash/reverse") for tree-shaking friendly bundles.

Summary

  • Purpose: _.reverse(array) flips element order in place and returns the same reference.
  • Immutable view: shallow-copy first (slice, spread, or concat) whenever observers rely on the prior ordering.
  • Next: Lodash _.slice(), _.remove() (previous), or the array methods hub.
Did you know?

Like _.fill() and _.pull(), _.reverse mutates the backing collection—reach for slice or a spread copy first when another reference still needs the original order.

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