Lodash _.identity() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Util utilities

What You’ll Learn

By the end of this tutorial, you’ll know when and why Lodash’s _.identity() returns values unchanged—and how it fits into maps, filters, and composition pipelines.

01

Core Syntax

_.identity(value) returns value.

02

No-Op Iteratee

Pass-through callback for _.map.

03

Truthy Filter

_.filter(arr, _.identity) drops falsy items.

04

Flow Pipelines

Placeholder step in _.flow.

05

vs constant

Pass-through vs fixed return.

06

vs arrow fn

When a named helper reads better.

What Is _.identity()?

_.identity() is the simplest Lodash util: it takes a value and returns it unchanged. Think of it as a named version of (x) => x—a pass-through or “no-op” transform.

💡
Beginner tip — function vs call

_.identity(42) returns 42. Passing _.identity (without calling it) gives you a function reference—useful as a callback: _.map([1, 2, 3], _.identity).

It looks trivial, but many Lodash methods accept iteratee callbacks. When you need “don’t transform this” without writing an inline arrow, _.identity documents that intent clearly.

📝 Syntax

Call it directly or pass the function reference as a callback:

javascript
_.identity(value)

Syntax Rules

  • value — any value; returned as-is.
  • Extra arguments — ignored; only the first argument is returned.
  • As callback — pass _.identity without parentheses to methods like _.map.
  • Reference equality — objects and arrays are returned by reference, not cloned.
javascript
import identity from "lodash/identity";



identity(42);           // 42

identity("hello");      // "hello"

identity(null);         // null



const nums = [1, 2, 3];

_.map(nums, identity);  // [1, 2, 3] — same values

⚡ Quick Reference

TaskCode patternResult
Return value_.identity(x)x
Map pass-through_.map(arr, _.identity)Copy of values
Filter truthy_.filter(arr, _.identity)Truthy items only
Sort by value_.sortBy(arr, _.identity)Ascending sort
Flow first step_.flow(_.identity, fn)Pass input to fn
Arrow equivalent(x) => xSame behavior
Returns
First arg

Unchanged value

Type
Function

Also usable as callback

Opposite
constant

Fixed return value

Category
Util

Functional helper

🧰 Parameters

What _.identity() accepts and returns:

value Optional

The value to return unchanged. When called with no arguments, returns undefined.

_.identity(42)
extra args Ignored

Only the first argument matters. Additional parameters from iteratee calls (index, collection) are ignored when identity is used as a callback.

_.identity(a, b, c) // a
return value Same reference

Primitives are returned by value; objects and arrays by reference—identity does not clone.

const o = {}; _.identity(o) === o
as callback Function ref

Pass _.identity without invoking it when a method expects an iteratee function.

_.map(arr, _.identity)

Need a deep clone instead of pass-through? Use structured cloning or a dedicated clone utility—not _.identity().

Examples Gallery

Practical _.identity() patterns with copy-ready code, sample output, and interactive Try It Yourself labs.

📚 Getting Started

Direct calls and the map iteratee pattern.

Example 1 — Return any value unchanged

Numbers, strings, booleans, null, and objects all pass through.

javascript
console.log(_.identity(42));        // 42

console.log(_.identity("hello"));   // "hello"

console.log(_.identity(false));     // false

console.log(_.identity(null));      // null



const obj = { a: 1 };

console.log(_.identity(obj) === obj); // true — same reference
Try It Yourself

How It Works

Identity is the baseline transform—everything else in a pipeline modifies the value; identity leaves it alone.

Example 2 — No-op map iteratee

When an API requires a mapping function but you want values unchanged.

javascript
const nums = [1, 2, 3, 4];



const mapped = _.map(nums, _.identity);



console.log(mapped);

// [1, 2, 3, 4]



console.log(mapped === nums); // false — new array, same values
Try It Yourself

How It Works

_.map always builds a new array; identity only means each element is copied without transformation. For primitives the values match; for objects the references are shared.

📈 Practical Patterns

Truthy filtering, flow pipelines, and default callbacks.

Example 3 — Filter truthy values

Used as a predicate, identity returns each element; _.filter keeps truthy results.

javascript
const mixed = [0, 1, "", "hi", false, null, 42];



console.log(_.filter(mixed, _.identity));

// [1, "hi", 42]



console.log(_.compact(mixed));

// [1, "hi", 42] — similar for arrays
Try It Yourself

How It Works

This is a common functional pattern: identity as predicate keeps truthy values. _.pickBy(obj) without a predicate uses a similar identity-style check on object values.

Example 4 — Pass-through in a flow pipeline

Use identity as the first step when you want to document “input unchanged, then transform.”

javascript
const double = (x) => x * 2;

const addTen = (x) => x + 10;



const pipeline = _.flow(_.identity, double, addTen);



console.log(pipeline(5));

// identity(5)=5, double(5)=10, addTen(10)=20

How It Works

The first step is a no-op here, but naming it with _.identity makes pipeline intent explicit. See _.flow() for left-to-right composition details.

🚀 Beyond the Basics

Default callbacks and comparison with related helpers.

Example 5 — Default transform callback

Use _.identity as the default when callers may omit a custom mapper.

javascript
function transformItems(items, mapper = _.identity) {

  return items.map(mapper);

}



console.log(transformItems([1, 2, 3]));

// [1, 2, 3] — default pass-through



console.log(transformItems([1, 2, 3], (n) => n * 10));

// [10, 20, 30]

How It Works

The old tutorial incorrectly suggested processValue(value = _.identity) returns data when omitted—it actually assigns the function as the parameter. Default callbacks should be invoked: mapper(item).

Example 6 — identity vs constant

Identity passes input through; constant always returns one fixed value.

javascript
console.log(_.identity(99));       // 99

console.log(_.identity(1));        // 1



const always99 = _.constant(99);

console.log(always99());           // 99

console.log(always99(1, 2, 3));    // 99 — args ignored

When to use which

Use _.identity when output should mirror input. Use _.constant() for stub handlers and fixed mock returns.

🧠 How _.identity() Works

1

Receive argument

Lodash takes the first parameter from the call or from an iteratee invocation.

Input
2

No transformation

No cloning, parsing, or coercion— the value is returned as-is.

No-op
3

Return unchanged

The same reference or primitive is handed back to the caller or next pipeline step.

Output
=

Same value out

Input equals output— the defining property of an identity function.

📝 Notes

  • _.identity does not clone objects—it returns the same reference.
  • Only the first argument is returned; extra iteratee args (index, collection) are ignored.
  • As a filter predicate, identity keeps truthy values—not the same as keeping all items.
  • Do not confuse with _.constant(), which ignores input and returns a fixed value.
  • Wrong pattern from older tutorials: _.filter(_.identity) is invalid—always pass a collection first.
  • Next in the series: _.iteratee() builds callbacks from shorthands.

Conclusion

_.identity() is Lodash’s named pass-through: return what you receive, or supply it as a no-op iteratee when an API demands a function.

Use it in maps, truthy filters, and flow pipelines; reach for _.constant() when you need a fixed return instead.

💡 Best Practices

✅ Do

  • Use _.identity when a callback slot must be filled with a no-op
  • Default mapper parameters to _.identity, then call it
  • Prefer identity over magic inline arrows in functional Lodash code
  • Use _.filter(arr, _.identity) for readable truthy filtering
  • Document pipeline steps with identity when input should pass through

❌ Don’t

  • Use identity expecting a deep clone of objects
  • Assign _.identity as a default data value— it is a function
  • Call _.filter(_.identity) without a collection argument
  • Swap identity for constant when output must depend on input
  • Overuse where omitting the iteratee is already clear

Key Takeaways

Knowledge Unlocked

Five things to remember about _.identity()

Use these points when you need a pass-through function.

5
Core concepts
📊 02

Map iteratee

No-op transform.

Practical
🔎 03

Filter truthy

Drop falsy items.

Pattern
🔗 04

Not constant

Input matters.

Compare
05

iteratee

Next: shorthands.

Next step

❓ Frequently Asked Questions

_.identity(value) returns the first argument unchanged. When used as a callback (for example _.map(arr, _.identity)), it passes each element through without transforming it.
They behave the same for a single argument. _.identity is a named, reusable function reference—handy when an API expects a function and you want a clear no-op transform.
_.identity returns whatever you pass in. _.constant(fixed) returns the same fixed value every call and ignores all arguments. Use identity for pass-through; use constant for always-return-this-value.
_.filter(collection, _.identity) keeps truthy values and removes falsy ones (0, false, '', null, undefined, NaN). It is a concise alternative to _.compact for arrays or a readable truthy filter.
You can use value = _.identity as a default callback parameter when the caller may omit a transform function—then invoke it as transform(item). Do not use it as a default value for data; it is a function reference, not a placeholder value.
Use it as a no-op iteratee in map/filter/sortBy, as the first or last step in _.flow pipelines, when APIs require a function but you want unchanged values, and anywhere a named pass-through reads clearer than an inline arrow.
Did you know?

In mathematics, an identity function satisfies f(x) = x for all x in its domain. Lodash’s _.identity is that idea in JavaScript— and it is the default iteratee behavior behind several collection methods when you omit a custom callback.

Practice _.identity() in the Live Editor

Open the Try It editor, run the examples, and experiment with pass-through callbacks.

Open Try It editor →

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