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.
Fundamentals
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.
Foundation
📝 Syntax
Pass any supported shorthand or callback shape:
javascript
_.iteratee(value)
Syntax Rules
Function — returned unchanged (already a callback).
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.
_.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.
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.
Important
📝 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.
Wrap Up
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.
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
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about _.iteratee()
Use these points when working with Lodash callback shorthands.
5
Core concepts
🔄01
Factory
Shorthand → fn.
Basics
📂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.