Lodash _.delay() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Function

Definition

Invokes func after wait milliseconds. Extra arguments are forwarded to func. Returns a timer id. 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 _.delay. Start with this line.

Lodash
_.delay(func, wait, [args])
CallWhat it does
_.delay(func, wait, [args])Primary signature.
_.delay(func)Wrap or transform a function.

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

Library declarations
Lodash
_.delay(func, wait, [args])

Parameters

ParameterDescription
funcRequired. Function to invoke later
waitRequired. Milliseconds to wait
argsOptional. Arguments forwarded to func

Return Value

Return ValueDescription
*Timer id (number)

Lodash Examples

Example 1 — Official: Delay a Log

Invoke a callback after a chosen wait with one argument.

Lodash
var message = "";

_.delay(function (text) {
  message = text;
}, 1000, "later");

// after 1000ms → message === "later"
Try It Yourself

How It Works

  1. Schedule. Lodash starts a 1000 ms timer with arg "later".
  2. Wait. Sync code can keep running.
  3. Invoke. Callback sets message to "later".
  4. Docs. Same idea as console.log("later") after one second.

Example 2 — Forward Multiple Arguments

Every value after wait is passed to func.

Lodash
var result = null;

_.delay(function (a, b) {
  result = a + " " + b;
}, 100, "hello", "world");

// after 100ms → result === "hello world"
Try It Yourself

How It Works

  1. Args. "hello" and "world" sit after the wait.
  2. Timer. After 100 ms, func receives both.
  3. Join. Result becomes "hello world".
  4. vs setTimeout. Avoids nesting args in a closure if you prefer this style.

Example 3 — Cancel With the Timer Id

Stop a scheduled call before it fires.

Lodash
var ran = false;

var id = _.delay(function () {
  ran = true;
}, 200);

clearTimeout(id);

// after wait → ran still false
Try It Yourself

How It Works

  1. Return. id is a timer handle.
  2. Cancel. clearTimeout(id) drops the callback.
  3. Result. ran stays false.
  4. Tip. Cancel on navigation / unmount when the wait is long.

Example 4 — wait of 0 Is Still Async

Zero wait does not run the function synchronously.

Lodash
var steps = [];

_.delay(function () {
  steps.push("delayed");
}, 0);

steps.push("sync");

// immediately: ["sync"]
// after timer:  ["sync", "delayed"]
Try It Yourself

How It Works

  1. Queue. Even 0 goes through the timer queue.
  2. Sync. "sync" is pushed right away.
  3. Later. "delayed" is appended after the stack.
  4. Similar. Close to _.defer for “asap async.”

Example 5 — delay vs defer

Choose an explicit wait or “after this stack.”

Lodash
var log = [];

_.defer(function () {
  log.push("defer");
});

_.delay(function () {
  log.push("delay");
}, 50);

// soon: ["defer"] then ["defer","delay"]
Try It Yourself

How It Works

  1. defer. Runs as soon as the stack clears (~1 ms).
  2. delay. Waits your 50 ms.
  3. Order. "defer" appears first.
  4. Pick. Use delay when the wait is part of the UX.

Browser & Runtime Support

_.delay 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. Built on timer APIs similar to setTimeout.

✓ Stable · Lodash 0.1+

_.delay()

Available in [email protected] full builds and the lodash/delay modular import. Works in evergreen browsers and current Node LTS 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
_.delay Lodash 0.1+

Bottom line: Safe for production once Lodash is loaded. Prefer import delay from "lodash/delay" for smaller builds. Native setTimeout is fine when you do not need Lodash’s arg-forwarding style.

Frequently Asked Questions

_.delay(func, wait, ...args) invokes func after wait milliseconds and forwards any extra arguments to func.
A timer id (number), like setTimeout — you can clearTimeout it.
delay uses your wait in ms. defer always schedules after the current stack with a tiny fixed delay.
Yes. A 0 wait still runs asynchronously on the timer queue — not synchronously.
Same idea. Lodash adds a consistent API and easy variadic arg forwarding: _.delay(fn, wait, a, b).
No. It schedules one invocation. Use setInterval or a loop of delays for repeats.

Next: _.flip()

Create a function that invokes func with arguments reversed.

_.flip() 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.

9 people found this page helpful