Lodash Wrapper .next() Method

Beginner
⏱️ 7 min read
📚 Updated: Jul 2026
🎯 6 Examples + 3 Try It
Seq & chaining

What You’ll Learn

By the end of this tutorial, you’ll use wrapper .next() to walk lazy Lodash sequences one step at a time with { done, value } results.

01

Iterator step

.next()

02

done + value

Result object.

03

Lazy chains

One item at a time.

04

vs .value()

All vs stepwise.

05

Loop pattern

while (!done).

06

With filter

Lazy filter seq.

What Is Wrapper .next()?

Wrapper .next() advances a lazy Lodash sequence one element at a time. Each call returns { done: boolean, value: any }—the same iterator shape used throughout JavaScript—so you can pull values manually instead of unwrapping everything with .value().

💡
Not _.prototype.next()

There is no _.prototype.next() function. Call .next() on a wrapper: _( [1, 2] ).next() returns { done: false, value: 1 }.

Use wrapper .next() for custom iteration over lazy chains—especially after filter or map when you want step-by-step control or deferred computation rather than materializing the full array upfront.

📝 Syntax

Call .next() on a wrapper with no arguments:

javascript
const wrapped = _([1, 2, 3]);
const step = wrapped.next();
// step -> { done: false, value: 1 }

Syntax Rules

  • No arguments — each call advances the lazy sequence by one yielded value.
  • Return shape — always { done, value }; check done before using value.
  • When done is true — iteration finished; value is undefined.
  • Lazy chains — works on wrappers with queued transforms (filter, map, etc.).
  • vs bulk unwrap — prefer .value() when you need the entire result at once.
javascript
import _ from "lodash";

const wrapped = _([1, 2]);

console.log(wrapped.next());
// -> { done: false, value: 1 }

console.log(wrapped.next());
// -> { done: false, value: 2 }

console.log(wrapped.next());
// -> { done: true, value: undefined }

⚡ Quick Reference

TaskCode patternResult
First element_(arr).next(){ done: false, value: 1 }
Loop until donewhile (!r.done) r = w.next()Step each value
Lazy filter_(arr).filter(fn).next()Yields matches only
All at once... .value()See .value()
Eager flush.commit()See .commit()
Native arraysfor...of arrSimpler for plain arrays
Step
.next()

One lazy value

Check
result.done

Stop when true

Bulk
.value()

All at once

🧰 Parameters

Wrapper .next() takes no arguments; each call returns one iterator result:

(no args) Required

Advance the lazy sequence by one step and return { done, value }.

wrapped.next()
done Boolean

false while more values exist; true when iteration is complete.

if (result.done) break;
value Any

The next yielded element when done is false; otherwise undefined.

result.value // next item
wrapper state Mutable

Each .next() moves the internal cursor forward on the same wrapper instance.

let r; while (!(r = w.next()).done) { }

For most apps, .value() or native for...of is simpler—use .next() when you need Lodash lazy sequence semantics.

Examples Gallery

Practical wrapper .next() patterns with sample output and interactive Try It Yourself labs.

📚 Getting Started

Call .next() repeatedly and read done and value from each result.

Example 1 — Three calls on a simple array

Walk [1, 2] one step at a time until done is true.

javascript
const wrapped = _([1, 2]);

console.log(wrapped.next());
// -> { done: false, value: 1 }

console.log(wrapped.next());
// -> { done: false, value: 2 }

console.log(wrapped.next());
// -> { done: true, value: undefined }
Try It Yourself

How It Works

Each .next() advances the lazy iterator on the wrapper. The final call signals completion with done: true.

Example 2 — Loop until done

Use a do...while pattern to collect every value from a longer sequence.

javascript
const wrapped = _([1, 2, 3]);
const collected = [];
let result;

do {
  result = wrapped.next();
  if (!result.done) {
    collected.push(result.value);
  }
} while (!result.done);

console.log(collected);
// -> [1, 2, 3]
Try It Yourself

📈 Practical Patterns

Lazy filters, custom processing, and when bulk unwrap is simpler.

Example 3 — Lazy filter with .next()

Only even numbers are yielded—computation happens one match at a time.

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

const evens = [];
let result;

while (true) {
  result = wrapped.next();
  if (result.done) break;
  evens.push(result.value);
}

console.log(evens);
// -> [2, 4]
Try It Yourself

Example 4 — Custom transform in the loop

Process each value as you pull it—here doubling every number.

javascript
const wrapped = _([10, 20, 30]);
const doubled = [];
let result;

while (true) {
  result = wrapped.next();
  if (result.done) break;
  doubled.push(result.value * 2);
}

console.log(doubled);
// -> [20, 40, 60]

🚀 Beyond the Basics

Compare stepwise iteration with bulk unwrap and know when each fits.

Example 5 — .next() vs .value()

Same data, different consumption style—manual steps versus one-shot unwrap.

javascript
const data = [1, 2, 3];

const stepwise = [];
let w = _(data);
let r;
while (!(r = w.next()).done) {
  stepwise.push(r.value);
}

const bulk = _(data).value();

console.log(JSON.stringify(stepwise) === JSON.stringify(bulk));
// -> true

Example 6 — When native loops are simpler

For plain arrays without lazy Lodash transforms, for...of is often clearer than .next().

javascript
const numbers = [1, 2, 3];
const sum = 0;

// Simple array — use native iteration
for (const n of numbers) {
  // process n
}

// Lazy Lodash filter — .next() shines
const wrapped = _(numbers).filter(function (n) { return n > 1; });
// pull with wrapped.next()...

🧠 How Wrapper .next() Works

1

Build a lazy wrapper

Start with _(data) or add transforms like filter and map on the wrapper.

Sequence
2

Call .next()

Lodash yields the next value as { done: false, value } or signals end with done: true.

Step
3

Repeat until done

Keep calling .next() on the same wrapper instance—the internal cursor advances each time.

Iterate
=

Or unwrap in bulk

When you do not need stepwise control, .value() materializes the full result in one call.

📝 Notes

  • There is no _.prototype.next() function—the correct name is wrapper .next() on a sequence object.
  • Always check result.done before using result.value—when done is true, value is undefined.
  • Wrapper .next() follows the same iterator protocol shape as generators and native iterators.
  • Especially useful after lazy filter or map when you want one element at a time.
  • For everyday array iteration, native for...of is usually simpler unless you need Lodash lazy chains.
  • Next in the series: .plant() clones a chain template onto new data.

Conclusion

Wrapper .next() lets you walk Lodash lazy sequences one step at a time using { done, value } results. It is ideal for custom loops, lazy filters, and iterator-style control when bulk .value() is not what you need.

Next in the wrapper prototype series: .plant(), which reuses a pipeline on a different wrapped value.

💡 Best Practices

✅ Do

  • Always check result.done before using result.value
  • Use a while or do...while loop for collecting all values
  • Prefer .next() on lazy filter/map chains when you need stepwise control
  • Use .value() when you need the full array or object at once
  • Reuse the same wrapper instance—each .next() advances its cursor

❌ Don’t

  • Call it _.prototype.next()—that name does not exist in Lodash
  • Read result.value when result.done is true
  • Use .next() on plain arrays when for...of is simpler
  • Expect .next() to return a wrapper—it returns { done, value }
  • Create a new wrapper for each step—that resets iteration from the start

Key Takeaways

Knowledge Unlocked

Five things to remember about wrapper .next()

Use these when stepping through lazy Lodash sequences manually.

5
Core concepts
02

Check done

Stop when true.

Critical
🔄 03

Lazy filter

One match at a time.

Pattern
📦 04

vs .value()

Step vs bulk.

Compare
🛠️ 05

When to use

Lazy chains.

Guideline

❓ Frequently Asked Questions

An object with done (boolean) and value. While elements remain, done is false and value is the next item. When finished, done is true and value is undefined.
.value() runs the entire chain and returns all results at once as plain data. .next() yields one lazy step at a time—useful for manual or memory-conscious iteration.
Same iterator shape { done, value }, but wrapper .next() walks a Lodash lazy sequence (often after map/filter on a wrapper), not a native array iterator directly.
When you want lazy, step-by-step consumption of a wrapped sequence—custom loops, pulling one item at a time, or integrating with iterator-style code.
No. The correct API is wrapper .next() on the object returned by _(value) or _.chain(value).
Yes. Chained transforms like filter create lazy sequences; .next() yields matching elements one by one without computing the full result upfront.
Did you know?

Wrapper .next() uses the standard JavaScript iterator result shape—the same { done, value } object you get from generators. That makes it familiar if you have used for await...of or manual generator iteration.

Practice Wrapper .next() in the Live Editor

Step through lazy sequences and lazy filters one value at a time.

Open Try It editor →

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.

6 people found this page helpful