Creates a function that caches the result of func. Later calls with the same cache key return the stored value instead of re-running the work. Part of Lodash 4.x Function (since 0.1.0).
Pass the required arguments shown below. Most helpers return a new function you call later.
Syntax
Call _.memoize. Start with this line.
Lodash
_.memoize(func, [resolver])
Call
What it does
_.memoize(func, [resolver])
Primary signature.
_.memoize(func)
Wrap or transform a function.
Prefer import memoize from "lodash/memoize" when you want a smaller bundle.
Library declarations
Lodash
_.memoize(func, [resolver])
Parameters
Parameter
Description
func
Required. Function whose results are cached
resolver
Optional. Builds the cache key from arguments
Return Value
Return Value
Description
*
Memoized function with .cache
Lodash Examples
Example 1 — Official: Memoize _.values
Different object keys store different results.
Lodash
var object = { a: 1, b: 2 };
var other = { c: 3, d: 4 };
var values = _.memoize(_.values);
values(object);
// → [1, 2]
values(other);
// → [3, 4]
Without a resolver, only the first arg is the key — use a resolver for both.
Lodash
var add = _.memoize(
function (a, b) {
return a + b;
},
function (a, b) {
return a + ":" + b;
}
);
add(2, 3);
// → 5
add(2, 4);
// → 6 // different key "2:4"
add(2, 3);
// → 5 // cache hit for "2:3"
Miss again. Next call recomputes and bumps calls to 2.
Compatibility
Browser & Runtime Support
_.memoize is a Lodash 4.x Function helper (since 0.1.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. There is no single native Function.memoize; Lodash provides a portable Map-style cache with an optional resolver.
✓ Stable · Lodash 4.x
_.memoize()
Available in [email protected] full builds and the lodash/memoize modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.
100%With Lodash 4.x
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · Modern WebView
Full support
_.memoizeLodash 4.x+
Bottom line: Safe for production once Lodash is loaded. Prefer import memoize from "lodash/memoize" for smaller builds. Ideal for expensive pure lookups, selectors, and API response shaping by key.
Frequently Asked Questions
_.memoize(func, [resolver]) returns a wrapped function that caches results. Repeated calls with the same cache key return the stored value without re-running func.
The first argument only. Extra arguments are ignored for the key unless you pass a resolver.
An optional function that receives the same arguments as the memoized call and returns the cache key to use.
Call memoized.cache.clear(), or use cache.delete(key) / cache.set(key, value) for individual entries.
once remembers one result forever (ignores later args). memoize caches many results keyed by argument.
Use import memoize from "lodash/memoize" or require("lodash/memoize") for tree-shaking. Full build: import _ from "lodash" then _.memoize.