Lodash _.after() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

The opposite of _.before — creates a function that invokes func once it is called n or more times. 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 _.after. Start with this line.

Lodash
_.after(n, func)
CallWhat it does
_.after(n, func)Primary signature.
_.after(func)Wrap or transform a function.

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

Library declarations
Lodash
_.after(n, func)

Parameters

ParameterDescription
nRequired. Call count before func starts (coerced with toInteger)
funcRequired. Function to invoke; throws if not a function

Return Value

Return ValueDescription
*New restricted function

Lodash Examples

Example 1 — Basic after(3)

Func stays quiet until the third call.

Lodash
var log = _.after(3, function () {
  return "fired";
});

log(); // → undefined
log(); // → undefined
log(); // → "fired"
Try It Yourself

How It Works

  1. Wrap. _.after(3, fn) returns a restricted function.
  2. Call 1–2. Counter decrements; fn is skipped → undefined.
  3. Call 3. Counter drops below 1 → fn runs and returns "fired".
  4. Use. Gate a “ready” action until enough signals arrive.

Example 2 — Official Parallel Barrier

Fire once when every item in a list has “completed”.

Lodash
var saves = ["profile", "settings"];
var messages = [];

var done = _.after(saves.length, function () {
  messages.push("done saving!");
});

_.forEach(saves, function (type) {
  // pretend asyncSave finished:
  done();
});

messages;
// → ["done saving!"]
Try It Yourself

How It Works

  1. Count. n equals saves.length (here 2).
  2. Share. Every completion path calls the same done wrapper.
  3. Barrier. After both calls, the log runs — matching the docs’ async-save idea.
  4. Sync demo. Real apps call done from async callbacks; timing may vary.

Example 3 — Early Calls Return undefined

Before the threshold, the wrapper has no return value from func.

Lodash
var ready = _.after(2, function () {
  return 42;
});

[ready(), ready()];
// → [undefined, 42]
Try It Yourself

How It Works

  1. First call. Counter still ≥ 1 after decrement → no func → undefined.
  2. Second call. Threshold hit → func returns 42.
  3. Check. Do not treat early returns as “false” work results — they never ran.
  4. Design. Prefer side effects (or a shared flag) over relying on early return values.

Example 4 — Keeps Running After n

From the nth call onward, every call invokes func again.

Lodash
var count = 0;
var tick = _.after(2, function () {
  count += 1;
  return count;
});

[tick(), tick(), tick(), tick()];
// → [undefined, 1, 2, 3]
Try It Yourself

How It Works

  1. Docs wording. Invokes func when called n or more times.
  2. Not once. Call 3 and 4 still run func — unlike _.once.
  3. Need once? Wrap with _.once, or ignore extra calls yourself.
  4. Contrast. _.before stops calling func after its limit.

Example 5 — after vs before

Same n, opposite timing windows.

Lodash
var aLog = [];
var bLog = [];

var a = _.after(3, function (x) { aLog.push(x); });
var b = _.before(3, function (x) { bLog.push(x); });

[1, 2, 3, 4].forEach(function (x) {
  a(x);
  b(x);
});

aLog; // → [3, 4]     // starts at call 3
bLog; // → [1, 2]     // stops before call 3
Try It Yourself

How It Works

  1. after(3). Skips 1–2; runs on 3 and 4.
  2. before(3). Runs on 1–2 (at most n − 1 times); freezes after.
  3. Pick. Barriers / “all done” → after. Caps / “first few only” → before.
  4. Args. Both forward this and arguments when they do call func.

Browser & Runtime Support

_.after is a Lodash 4.x Function helper (since 0.1.0). It needs no special browser APIs beyond loading Lodash.

✓ Stable · Lodash 0.1.0+

_.after()

Available in [email protected] full builds and the lodash/after modular import. Works in evergreen browsers and Node / Bun / Deno when Lodash is installed.

100% With Lodash 4.x
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
_.after Lodash 4.x+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer import after from "lodash/after" for smaller builds.

Frequently Asked Questions

_.after(n, func) returns a new function that invokes func once it has been called n or more times. Earlier calls return undefined.
after waits until the nth call, then runs func on that call and every later call. before runs func only while the call count is below n, then freezes on the last result.
Yes. From the nth call onward, every invocation of the wrapper calls func again (unlike _.once).
Lodash coerces n with toInteger. When n is 0 or less, func runs on the first call.
_.after throws a TypeError with the message "Expected a function".
Use import after from "lodash/after" or require("lodash/after") for tree-shaking. Full build: import _ from "lodash" then _.after.

Next: _.ary()

Cap how many arguments reach a function — classic fix for map + parseInt.

_.ary() tutorial →

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