Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2016.
The next() method of Generator instances returns an object with two properties done and value. You can also provide a parameter to the next method to send a value to the generator.
The value to send to the generator.
The value will be assigned as a result of a yield expression. For example, in variable = yield expression, the value passed to the .next() function will be assigned to variable.
An Object with two properties:
doneA boolean value:
Any JavaScript value yielded or returned by the generator.
Thrown if the generator is already running.
The following example shows a generator and the object that the next method returns:
In this example, getPage takes a list and "paginates" it into chunks of size pageSize. Each call to next will yield one such chunk.
In this example, next is called with a value.
Note: The first call does not log anything, because the generator was not yielding anything initially.
| ECMAScript® 2027 Language Specification # sec-generator.prototype.next |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Jul 10, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.