The Iterator Result Object
What you'll learn: You'll discover the exact structure and meaning of the object that every iterator returns when you call its next() method.
What Is the Iterator Result Object?
Every time you call next() on an iterator, you get back an object with two properties: value and done. This is called the iterator result object, and it's the standard way iterators communicate their state.
The object has this shape:
{
value: /* the current element */,
done: /* true or false */
}
value: The current item from the collection (like an array element or object property)done: A boolean that tells you whether the iteration is finished
Think of It Like a Ticket Dispenser
Imagine a ticket dispenser at a deli counter. Each time you press the button (next()), you get a ticket with two pieces of information:
- The ticket number (the
value) - Whether there are more tickets available (inverse of
done)
When the last ticket is dispensed, done becomes true.
How It Works in Practice
const arr = ['a', 'b', 'c'];
const iterator = arr[Symbol.iterator]();
console.log(iterator.next()); // { value: 'a', done: false }
console.log(iterator.next()); // { value: 'b', done: false }
console.log(iterator.next()); // { value: 'c', done: false }
console.log(iterator.next()); // { value: undefined, done: true }
Notice that when done is true, value is typically undefined (though this can vary).
Why This Structure Matters
The iterator result object is a contract. Any code that works with iterators expects this exact format, which is why for...of loops and other iteration tools work seamlessly with any iterable.
Key Takeaway: The iterator result object { value, done } is the standardized response from calling next() on an iterator—value holds the current item, and done signals whether iteration is complete.