Lodash _.iteratee() Method

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

What You’ll Learn

By the end of this tutorial, you’ll understand how Lodash turns strings, objects, and functions into reusable iteratee callbacks with _.iteratee().

01

Core Syntax

_.iteratee(value) returns a function.

02

Property String

'age' becomes a getter.

03

Matcher Object

{ role: 'admin' } becomes a predicate.

04

Function Pass-through

Custom callbacks returned as-is.

05

Implicit Shorthand

_.map(arr, 'key') uses same rules.

06

vs identity

Null/undefined → pass-through.

What Is _.iteratee()?

Lodash collection methods like _.map, _.filter, and _.sortBy accept more than plain functions—they also accept property name strings and matcher objects as shorthand. _.iteratee() is the factory that converts those shorthands into real callback functions.

💡
Beginner tip — explicit vs built-in

_.map(people, 'age') already uses iteratee rules internally. _.iteratee('age') is the same getter, but stored once so you can reuse it: const getAge = _.iteratee('age').

Think of _.iteratee() as Lodash’s “callback normalizer”—one entry point that turns many input shapes into a function your loop can call.

📝 Syntax

Pass any supported shorthand or callback shape:

javascript
_.iteratee(value)

Syntax Rules

  • Function — returned unchanged (already a callback).
  • String — property accessor: obj => obj[key] (supports paths like 'user.name').
  • Array — path segments: ['user', 'name'].
  • Plain object — partial-match predicate (same idea as _.matches()).
  • null / undefined — returns _.identity.
javascript
import iteratee from "lodash/iteratee";



const people = [

  { name: "John", age: 30 },

  { name: "Jane", age: 25 },

];



const getAge = iteratee("age");

people.map(getAge); // [30, 25]

⚡ Quick Reference

Input to _.iterateeResulting callbackTypical use
'age'obj => obj.ageMap / sortBy property
['user', 'id']Nested getterDeep property access
{ active: true }Partial-match predicateFilter / find
(x) => x * 2Same functionCustom transform
null_.identityPass-through default
Shorthand in _.mapAuto-converted_.map(arr, 'key')
Returns
Function

Normalized callback

String in
Getter

Property access

Object in
Matcher

Partial compare

Category
Util

Callback factory

🧰 Parameters

What you pass to _.iteratee() and what comes back:

value Required

The shorthand or callback to normalize. Type determines the returned function’s behavior.

_.iteratee("name")
function input As-is

If you already pass a function, Lodash returns it directly—no extra wrapping.

_.iteratee((n) => n * 2)
object input Predicate

Creates a function that returns true when the element partially matches the object (deep comparison on listed keys).

_.iteratee({ role: "admin" })
return value Function

A callback invoked as fn(element) (plus index/collection when used inside Lodash iteration).

const fn = _.iteratee("age")

Matcher objects use the same partial-match rules as _.matches()—only properties you list are checked.

Examples Gallery

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

📚 Getting Started

Property getters and matcher predicates.

Example 1 — Property string getter

Turn 'age' into a function that plucks that field from each object.

javascript
const people = [

  { name: "John", age: 30 },

  { name: "Jane", age: 25 },

];



const getAge = _.iteratee("age");



console.log(people.map(getAge));

// [30, 25]



// Equivalent shorthand — no explicit _.iteratee needed:

console.log(_.map(people, "age"));

// [30, 25]
Try It Yourself

How It Works

The string shorthand saves you from writing (person) => person.age every time. Store the iteratee when the same getter is reused across methods.

Example 2 — Matcher object predicate

An object input becomes a filter predicate with partial-match semantics.

javascript
const users = [

  { name: "Alice", role: "user", active: true },

  { name: "Bob", role: "admin", active: true },

  { name: "Carol", role: "admin", active: false },

];



const isAdmin = _.iteratee({ role: "admin" });



console.log(_.filter(users, isAdmin));

// Bob and Carol — role matches; active is not checked
Try It Yourself

How It Works

Only keys listed in the matcher object are compared. Add { role: 'admin', active: true } to require both. Same rules as _.matches().

📈 Practical Patterns

Custom functions, sorting, and reusable factories.

Example 3 — Function pass-through

Pass a custom predicate—_.iteratee returns it unchanged.

javascript
const numbers = [1, 2, 3, 4, 5];

const isEven = (n) => n % 2 === 0;



const predicate = _.iteratee(isEven);



console.log(_.filter(numbers, predicate));

// [2, 4]



// Wrapping is optional — same result:

console.log(_.filter(numbers, isEven));

How It Works

Wrapping an existing function is redundant for one-off calls but useful when your utility accepts “anything iteratee accepts” and normalizes with _.iteratee(input) first.

Example 4 — Sort by property

Iteratee getters work with _.sortBy—shorthand is usually enough.

javascript
const products = [

  { name: "Laptop", price: 1000 },

  { name: "Phone", price: 800 },

  { name: "Tablet", price: 500 },

];



console.log(_.sortBy(products, "price"));

// ascending by price



console.log(_.sortBy(products, _.iteratee("price")));

// same result — explicit iteratee

How It Works

_.sortBy converts the second argument through iteratee rules automatically. Explicit _.iteratee('price') documents the getter when passed to your own helper.

🚀 Beyond the Basics

Reusable factories and the identity default.

Example 5 — Reusable iteratee factory

Build one callback from user config, then use it in map and filter.

javascript
function buildReport(records, field) {

  const getter = _.iteratee(field);

  const values = records.map(getter);

  const max = Math.max(...values);

  const top = records.filter((r) => getter(r) === max);

  return { values, top };

}



const scores = [

  { name: "Alice", score: 85 },

  { name: "Bob", score: 90 },

];



console.log(buildReport(scores, "score"));

// values: [85, 90], top: [{ name: 'Bob', score: 90 }]
Try It Yourself

How It Works

Because field can be a string, path, or function, _.iteratee(field) normalizes it once—your helper stays flexible without a chain of if checks.

Example 6 — Null returns identity

Omitting the shorthand falls back to pass-through behavior.

javascript
const passThrough = _.iteratee();



console.log(passThrough === _.identity); // true in Lodash 4



console.log(_.map([1, 2, 3], passThrough));

// [1, 2, 3]

Connection to identity

_.identity() is the default iteratee when no transform is specified. _.iteratee() with no value returns that same function.

🧠 How _.iteratee() Works

1

Inspect input type

Lodash checks whether value is a function, string, array, object, or nullish.

Dispatch
2

Build callback

Property → getter, object → matcher, function → as-is, null → identity.

Factory
3

Return function

The callback is ready for map, filter, sortBy, or your own iteration.

Output
=

Reusable iteratee

One normalized callback—same rules Lodash uses internally for collection shorthands.

📝 Notes

  • Most Lodash methods already apply iteratee rules—explicit _.iteratee() is for reuse and custom utilities.
  • Matcher objects use partial comparison—only listed keys are checked.
  • Property strings support dot paths: 'user.name' and array paths ['user', 'name'].
  • Wrapping an existing function in _.iteratee(fn) is a no-op but helps normalize mixed input types.
  • _.iteratee() with no argument returns _.identity.
  • Next in the series: _.matches() for dedicated partial-match predicates.

Conclusion

_.iteratee() is Lodash’s callback factory—turn property names, matcher objects, and functions into one normalized iteratee you can reuse anywhere.

For everyday _.map and _.filter calls, shorthand arguments are enough. Reach for _.iteratee() when you build flexible helpers or store callbacks for later.

💡 Best Practices

✅ Do

  • Use shorthand strings directly in one-off _.map(arr, 'key') calls
  • Store _.iteratee(field) when the same getter runs in multiple steps
  • Normalize user-supplied callback config with _.iteratee in custom utils
  • Use matcher objects for readable filter predicates
  • Document which shorthand types your API accepts

❌ Don’t

  • Wrap every callback in _.iteratee() when shorthand already works inline
  • Confuse property getters with matcher objects—they serve different roles
  • Assume matcher objects check every property on the element
  • Use iteratee object shorthand when you meant to pluck a nested object field
  • Forget that _.iteratee({ score: 90 }) is for matching, not extracting

Key Takeaways

Knowledge Unlocked

Five things to remember about _.iteratee()

Use these points when working with Lodash callback shorthands.

5
Core concepts
📂 02

String

Property getter.

Map / sort
🔎 03

Object

Matcher predicate.

Filter
🛠 04

Reuse

Store once.

Practical
05

matches

Related helper.

Next step

❓ Frequently Asked Questions

_.iteratee(value) converts shorthand values into callback functions. A property name becomes a getter, an object becomes a partial-match predicate (like _.matches), a function is returned as-is, and null/undefined becomes _.identity.
Usually no. Lodash collection methods already convert shorthands internally—_.map(users, 'age') works without wrapping. Use _.iteratee() when you need to build or store a callback once and reuse it, or when your own API expects a normalized function.
Functions (returned unchanged), property name strings (e.g. 'age'), path arrays (e.g. ['user', 'name']), plain objects (partial match predicate), and null/undefined (identity pass-through).
_.iteratee('age') extracts a property value from each element. _.iteratee({ role: 'admin' }) returns a predicate that checks whether each element partially matches that object—useful in _.filter, not for mapping values.
_.iteratee() with no argument or null/undefined returns _.identity—the default pass-through iteratee Lodash uses when you omit a callback in some methods.
Use it to create reusable callbacks, normalize user input in your own utilities, document intent when building iteratee factories, or mirror Lodash shorthand rules in custom iteration helpers.
Did you know?

When you write _.map(users, 'email'), Lodash internally converts 'email' through the same iteratee machinery as _.iteratee('email'). The explicit form shines when you need that callback in more than one place or inside your own functions.

Practice _.iteratee() in the Live Editor

Open the Try It editor, run the examples, and build reusable callback factories.

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