iterator.take(limit) returns a new lazy iterator that yields at most limit values from the source. After that many values (or when the source ends earlier), the helper stops.
limit is a number: how many values to keep from the front. Chain other helpers before or after take(), then use toArray() or for...of when you want the results.
Remember
iterator.take(limit)
limit 3 → at most the first 3 values
source shorter → yields only what exists
returns → a new lazy iterator
Useful after map/filter, or before toArray()
Pair with drop() to skip then keep
Syntax
Call take() on an iterator and pass how many values you want from the start.
// Iterator helpers (Baseline Newly available)
Iterator.prototype.take(limit)
// limit : number of values to keep from the start
// returns : a new lazy iterator helper
Parameters
Parameter
Description
limit
Required. A number saying how many values to yield at most. Use a non-negative integer such as 0, 1, or 3.
Return Value
Return Value
Description
Iterator helper
A new lazy iterator that yields at most limit values, then ends. Collect with toArray() or loop with for...of.
JavaScript Examples
Example 1 — Take the First Three Values
Start with [1, 2, 3, 4, 5].values(), keep only the first three, and collect with toArray().
The Try It page first checks that iterator.take() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Start with five numbers. The iterator can yield 1 through 5.
Limit to three.take(3) allows only the first three values.
Collect the slice.toArray() prints [1, 2, 3].
Example 2 — Filter Then Take a Limit
Keep even numbers first, then take only the first two matches.
JavaScript
const result = [1, 2, 3, 4, 5, 6].values()
.filter((n) => n % 2 === 0)
.take(2)
.toArray();
console.log(result);
The Try It page first checks that iterator.take() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Keep the evens. The filter would allow 2, 4, and 6.
Stop after two.take(2) yields only 2 and 4.
Collect the result.toArray() shows [2, 4].
Example 3 — Take Values from a Generator
Yield several colors from a generator, take the first two, and print with for...of.
JavaScript
function* colors() {
yield "red";
yield "green";
yield "blue";
yield "yellow";
}
const firstTwo = colors().take(2);
for (const color of firstTwo) {
console.log(color);
}
The Try It page first checks that iterator.take() exists, because Iterator helpers are still new. In an older browser it prints a short explanation and the output above. In a current browser it runs the code for real.
How It Works
Yield four colors. The generator can produce red, green, blue, and yellow.
Keep only two.take(2) stops after the first two yields.
Print as you go.for...of shows red then green.
Compatibility
Browser & Runtime Support
Iterator.prototype.take() is an Iterator helper (Baseline Newly available since March 2025). It works in current browsers and in Node.js 22 or newer.
✓ Baseline 2025 · Newly available
iterator.take()
Supported in Chrome 122+, Edge 122+, Firefox 131+, Safari 18.4+, Opera 108+ and Node.js 22+. Internet Explorer never got it.
2025Standard since
Google Chrome122+ · Desktop & Mobile
Full support
Microsoft Edge122+ · Chromium based
Full support
Mozilla Firefox131+ · Desktop & Mobile
Full support
Apple Safari18.4+ · macOS & iOS
Full support
Opera108+ · Chromium based
Full support
Samsung Internet26+ · Android
Supported
Android WebView122+ · Chromium based
Supported
Node.js22+ · Server runtime
Supported
DenoRecent versions · JavaScript runtime
Supported
BunRecent versions · JavaScript runtime
Supported
Internet ExplorerNo native support
Not supported
iterator.take()Current browsers
Bottom line: Check support with a typeof test before you use it in older browsers. Prefer chaining helpers and calling toArray() last.
Frequently Asked Questions
It returns a lazy iterator that yields at most limit values from the start of the source, then ends.
take() yields every available value and then stops. You get a shorter list, not an error.
No. It returns another iterator helper. Call toArray() or use for...of when you want the values collected or printed.
take(n) keeps the first n values. drop(n) skips the first n values and yields the rest.
Yes. Filter or map first, then take a limit, or take first and then transform. Collect once at the end.