Lodash _.flip() method

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

What you’ll learn

  • How _.flip reverses arguments passed into the wrapped function.
  • How flip differs from _.rearg and from mutating arrays.
  • Practical patterns with binary helpers and variadic functions.
  • How to avoid surprises with arity and third-party callbacks.

Prerequisites

Optional read: _.delay(), _.curryRight(), and the Function hub.

  • First-class functions: passing functions as values and returning new functions.
  • The arguments object: helpful when flipping variadic callbacks.

Overview

_.flip(func) returns a wrapper that invokes func with arguments reversed. It fits Lodash’s family of function decorators alongside curry and bind helpers.

Syntax

javascript
_.flip(func)
  • func: function to wrap.
  • returns: new function that reverses arguments before calling func.
1

Variadic arguments reversed

Classic lodash illustration: collect arguments after flipping so order mirrors the reversed parameter list.

javascript
import flip from "lodash/flip";

const flipped = flip(function () {
  return Array.from(arguments);
});

flipped("a", "b", "c", "d");
// ["d", "c", "b", "a"]
2

Binary subtraction

For two parameters, flip swaps operands—useful when an API passes arguments opposite to your helper.

javascript
import flip from "lodash/flip";

const subtract = (a, b) => a - b;
const flippedSubtract = flip(subtract);

subtract(10, 3);
// 7

flippedSubtract(10, 3); // calls subtract(3, 10)
// -7
3

String concat order

Adapt a small formatter without rewriting its body—flip swaps which string lands first.

javascript
import flip from "lodash/flip";

const joinTwo = (first, second) => first + second + "!";

flip(joinTwo)("world", "hello ");
// "hello world!"

📋 _.flip vs _.rearg vs array reverse

ToolWhat changesTypical use
_.flipEvery argument position mirrored left-rightSwap parameter order for binary or variadic functions
_.reargCustom permutation you definePick arbitrary reorderings beyond full reversal
_.reverseMutates an array’s elementsList ordering—not function signatures

Pitfalls to avoid

Arity

Unary helpers

Flipping a single-parameter function is effectively a no-op aside from wrapper overhead.

Arrays

One array argument

flip reverses discrete parameters; it does not reverse elements inside an array you pass as one value.

this

Bound methods

Combine flip with bind carefully—caller context still flows through lodash wraps.

❓ FAQ

It returns a new function that calls the original with its arguments reversed left-to-right.
No. flip reorders parameters at invoke time; _.reverse mutates arrays in place.
flip always reverses all arguments; rearg applies a custom permutation you supply.
Like other lodash wraps, metadata such as arity hints may be adjusted on the wrapper—treat the wrapper as the callable you export.
When an API expects (b, a) but you already wrote (a, b), or when adapting callbacks without rewriting the inner implementation.

Summary

Did you know?

Lodash builds _.flip with createWrap(func, WRAP_FLIP_FLAG) (WRAP_FLIP_FLAG is 512), wiring argument reversal into the same meta wraps system used by curry and bind helpers.

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