Lodash _.prototype.next() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Seq

Definition

Gets the next value on a wrapped object following the iterator protocol. Call it on a Lodash wrapper from _(value) or _.chain(value). Part of Lodash Seq (since 4.0.0).

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

Syntax

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

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

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

Library declarations
Lodash
wrapper.next()

Parameters

ParameterDescription
ReceiverRequired. A Lodash wrapper instance

Return Value

Return ValueDescription
*{ done: boolean, value: * }

Lodash Examples

Example 1 — Official Steps

Call .next() three times on _([1, 2]).

Lodash
var wrapped = _([1, 2]);

[
  wrapped.next(),
  wrapped.next(),
  wrapped.next()
];
// → [
//   { done: false, value: 1 },
//   { done: false, value: 2 },
//   { done: true,  value: undefined }
// ]
Try It Yourself

How It Works

  1. Wrap. _([1, 2]) creates a Seq wrapper.
  2. Step 1–2. Each .next() yields the next number with done: false.
  3. Step 3. Past the end → done: true, value: undefined.
  4. Docs. Matches the official Lodash example.

Example 2 — Loop Until done

Collect values in a simple while loop.

Lodash
var wrapped = _(["a", "b", "c"]);
var step;
var out = [];

while ((step = wrapped.next()), !step.done) {
  out.push(step.value);
}

out;
// → ["a", "b", "c"]
Try It Yourself

How It Works

  1. Call. Each loop iteration requests one .next().
  2. Guard. Stop when step.done is true.
  3. Collect. Push step.value while items remain.
  4. Result. Same data as unwrapping — pulled one by one.

Example 3 — After filter

Step through a filtered chain.

Lodash
var wrapped = _([1, 2, 3, 4]).filter(function (n) {
  return n % 2 === 0;
});

[
  wrapped.next(),
  wrapped.next(),
  wrapped.next()
];
// → [
//   { done: false, value: 2 },
//   { done: false, value: 4 },
//   { done: true,  value: undefined }
// ]
Try It Yourself

How It Works

  1. Chain. .filter keeps even numbers.
  2. Materialize. The first .next() resolves the chain into values.
  3. Steps. Yields 2, then 4, then finished.
  4. Use. Handy when you only need a few matches, not the full array.

Example 4 — next vs value

Stepwise results vs one plain array.

Lodash
var a = _([10, 20]);
var b = _([10, 20]);

[
  a.next(),
  a.next(),
  b.value()
];
// → [
//   { done: false, value: 10 },
//   { done: false, value: 20 },
//   [10, 20]
// ]
Try It Yourself

How It Works

  1. next. Returns iterator result objects.
  2. value. Returns the full plain array at once.
  3. State. Each wrapper keeps its own cursor for .next().
  4. Rule. Need everything now → .value(); need steps → .next().

Example 5 — for…of on a Wrapper

Wrappers are iterable via Symbol.iterator (since 4.0.0).

Lodash
var wrapped = _([1, 2, 3]);
var out = [];

for (var n of wrapped) {
  out.push(n);
}

out;
// → [1, 2, 3]

// wrapped[Symbol.iterator]() === wrapped
// → true
Try It Yourself

How It Works

  1. Iterable. The wrapper is its own iterator.
  2. Loop. for…of calls the iterator protocol under the hood.
  3. Values. You get plain elements, not { done, value } objects.
  4. Same idea. Manual .next() exposes the raw iterator result shape.

Browser & Runtime Support

Wrapper .next() is a Lodash Seq prototype method (since 4.0.0). It follows the JS iterator result shape and needs no special browser APIs beyond loading Lodash.

✓ Stable · Lodash 4.0.0+

_.prototype.next()

Available in [email protected] full builds when using _(value) / _.chain(value). Works in evergreen browsers and Node / Bun / Deno when Lodash is installed. for…of needs Symbol.iterator support (all modern engines).

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

An object shaped like the iterator protocol: { done, value }. While items remain, done is false and value is the next element. When finished, done is true and value is undefined.
.value() runs the whole chain and returns all results at once as plain data. .next() yields one step at a time from the wrapped sequence.
No. Call it on a wrapper from _(value) or _.chain(value). Docs list it as _.prototype.next().
No. Call wrapped.next() with empty parentheses each time you want the next step.
Yes. Build a chain like _([1,2,3,4]).filter(n => n % 2 === 0), then call .next() to pull matching values one by one.
Yes. Lodash wrappers implement Symbol.iterator (since 4.0.0), so for...of works; each iteration uses the same iterator idea as .next().

Next: .plant()

Reuse the same chain actions on a different starting value.

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

7 people found this page helpful