Lodash _.prototype.commit() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Seq

Definition

Executes the chain sequence and returns the wrapped result. Call it on a Lodash wrapper from _(value) or _.chain(value). Part of Lodash Seq (since 3.2.0).

Call it on a Lodash wrapper. Finish with .value() when you need a plain result.

Syntax

Call _.prototype.commit(). Start with this line.

Lodash
wrapper.commit()
CallWhat it does
wrapper.commit()Primary signature.

Prefer import _ from "lodash" (full build) when you need wrapper prototype helpers.

Library declarations
Lodash
wrapper.commit()

Parameters

ParameterDescription
ReceiverRequired. A Lodash wrapper instance

Return Value

Return ValueDescription
*New wrapper around the flushed value

Lodash Examples

Example 1 — Deferred push

Mutations wait until commit (or unwrap).

Lodash
var array = [1, 2];
var wrapped = _(array).push(3);

JSON.stringify(array);
// → "[1,2]"

wrapped = wrapped.commit();

JSON.stringify(array);
// → "[1,2,3]"
Try It Yourself

How It Works

  1. Queue. .push(3) is pending on the wrapper.
  2. Before. The original array is still [1, 2].
  3. Flush. .commit() runs the queue (via .value() under the hood).
  4. After. array is [1, 2, 3] and you still have a wrapper.

Example 2 — Commit, Then Keep Chaining

Flush, then call more wrapper methods.

Lodash
var array = [1, 2];
var wrapped = _(array).push(3).commit();

wrapped.last();
// → 3

JSON.stringify(array);
// → "[1,2,3]"
Try It Yourself

How It Works

  1. Commit. Applies push(3) and returns a wrapper.
  2. Continue. .last() reads from the updated array.
  3. Result. Last element is 3.
  4. Docs. Matches the official follow-up after commit.

Example 3 — commit vs value

Same flush; different return type.

Lodash
var a = [1, 2];
var b = [1, 2];

var afterCommit = _(a).push(3).commit();
var afterValue = _(b).push(4).value();

typeof afterCommit.value === "function";
// → true   (still a wrapper)

Array.isArray(afterValue);
// → true   (plain array [1, 2, 4])
Try It Yourself

How It Works

  1. Both flush. Each applies its pending push.
  2. commit. Re-wraps so .value is still a method.
  3. value. Returns the plain array and ends the chain.
  4. Rule. Need more steps → commit; done → value.

Example 4 — Deferred reverse

Another mutating method that waits for a flush.

Lodash
var array = [1, 2, 3];
var wrapped = _(array).reverse();

JSON.stringify(array);
// → "[1,2,3]"

wrapped.commit();

JSON.stringify(array);
// → "[3,2,1]"
Try It Yourself

How It Works

  1. Queue. .reverse() is deferred on the wrapper.
  2. Before. Original order unchanged.
  3. Commit. Flush mutates array in place.
  4. After. Array is [3, 2, 1].

Example 5 — Commit Mid-Chain

Flush once, then queue another mutation.

Lodash
var array = [1, 2];

_(array)
  .push(3)
  .commit()
  .push(4)
  .commit();

JSON.stringify(array);
// → "[1,2,3,4]"
Try It Yourself

How It Works

  1. First commit. Applies push(3) → [1, 2, 3].
  2. Second queue. push(4) waits again.
  3. Second commit. Flushes → [1, 2, 3, 4].
  4. Pattern. Use mid-chain commits when outer code must see side effects early.

Browser & Runtime Support

Wrapper .commit() is a Lodash Seq prototype method (since 3.2.0). It needs no special browser APIs beyond loading Lodash.

✓ Stable · Lodash 3.2.0+

_.prototype.commit()

Available in [email protected] full builds when using _(value) / _.chain(value). Works in evergreen browsers and Node / Bun / Deno when Lodash is installed.

100% With Lodash 3.2.0+
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
.commit() Lodash 3.2.0+

Bottom line: Safe for production once Lodash is on the page or in your bundle. Prefer the full lodash build for Seq / wrapper APIs.

Frequently Asked Questions

It executes the chain sequence eagerly and returns a new Lodash wrapper. Internally it is like new LodashWrapper(this.value(), this.__chain__). Official docs: run pending steps, keep wrapping.
.value() runs pending steps and returns plain data — the chain ends. .commit() runs the same flush but re-wraps the result so you can keep chaining.
When mutating methods like push() or reverse() defer changes, and you need those side effects applied to the original value before the next step or before reading the array outside the chain.
No. Call wrapped.commit() with empty parentheses. It flushes the current pending queue and returns a wrapper.
No. The API is wrapper .commit() on the object from _(value) or _.chain(value). Docs list it as _.prototype.commit().
Yes — that is the point. After commit you still have a wrapper. Use .value() only when you need the final plain result.

Next: .next()

Step through a lazy Lodash sequence with the iterator protocol.

.next() 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.

8 people found this page helpful