Lodash _.identity() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Util

Definition

Returns the first argument it receives — unchanged. Part of Lodash Util since 0.1.0 (stable — not deprecated).

Note: Objects and arrays are returned by the same reference (not cloned). Extra arguments after the first are ignored.

Syntax

Call _.identity. Start with this line.

Lodash
_.identity(value)
CallWhat it does
_.identity(value)Primary signature.
_.identity(...)Call the util helper.

Prefer import identity from "lodash/identity" when you want a smaller bundle.

Library declarations
Lodash
_.identity(value)

Parameters

ParameterDescription
valueRequired. Any value to return

Return Value

Return ValueDescription
*The same value

Lodash Examples

Example 1 — Official: Same Object Reference

Confirm the returned object is the input itself.

Lodash
var object = { a: 1 };

console.log(_.identity(object) === object);
// → true
Try It Yourself

How It Works

  1. Create. One object in memory.
  2. Pass through. _.identity(object) returns that object.
  3. Compare. === is true — same reference.
  4. Not a clone. No new { a: 1 } is allocated.

Example 2 — Return Any Value

Primitives and strings pass through the same way.

Lodash
_.identity(42);
// → 42

_.identity("hello");
// → "hello"
Try It Yourself

How It Works

  1. Number. Returns 42 unchanged.
  2. String. Returns "hello" unchanged.
  3. Rule. First argument in → same value out.
  4. Use. Handy when an API requires a function.

Example 3 — _.map with Identity

Pass _.identity as a no-op iteratee.

Lodash
_.map([1, 2, 3], _.identity);
// → [1, 2, 3]
Try It Yourself

How It Works

  1. Iterate. _.map calls the iteratee per item.
  2. Pass-through. Each call returns the element itself.
  3. Result. A new array with the same values.
  4. Why. Useful as a default transform placeholder.

Example 4 — Filter Truthy Values

Use identity as a predicate — falsy values drop out.

Lodash
_.filter([0, 1, false, 2, "", 3], _.identity);
// → [1, 2, 3]
Try It Yourself

How It Works

  1. Predicate. Filter keeps items where the callback is truthy.
  2. Identity. Returns the item — so falsy items fail.
  3. Dropped. 0, false, and "" are removed.
  4. Kept. 1, 2, 3 remain.

Example 5 — identity vs constant

Echo the input vs always return a fixed value.

Lodash
_.identity(7);
// → 7

_.constant(7)();
// → 7

_.identity(99);
// → 99

_.constant(7)(99);
// → 7
Try It Yourself

How It Works

  1. identity. Returns whatever you pass.
  2. constant. Returns the captured 7 every time.
  3. With 99. Identity yields 99; constant still yields 7.
  4. Choose. Pass-through → identity; fixed stub → constant.

Browser & Runtime Support

_.identity is a Lodash Util helper since 0.1.0. It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash.

✓ Stable · Lodash 0.1.0+

_.identity()

Available in [email protected] full builds and the lodash/identity modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 0.1+
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
_.identity Lodash 0.1.0+

Bottom line: Safe for production once Lodash is loaded. Prefer import identity from "lodash/identity" for smaller bundles. Use it as a named pass-through iteratee or default transform.

Frequently Asked Questions

_.identity(value) returns value unchanged. Official: _.identity(object) === object is true — same reference, not a clone.
Same behavior for one argument. _.identity is a named Lodash helper you can pass by reference to map, filter, flow, and other APIs.
_.identity returns what you pass in. _.constant(v) always returns the fixed v and ignores arguments.
_.filter(arr, _.identity) keeps truthy values and drops falsy ones — a concise truthy filter.
No. It returns the same reference. Mutating the result mutates the original.
Use import identity from "lodash/identity" or require("lodash/identity"). Full build: import _ from "lodash" then _.identity.

Next: _.iteratee()

Turn property names, objects, and functions into iteratee callbacks.

_.iteratee() tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

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.

10 people found this page helpful