JavaScript Iterator take() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Instance method

Definition

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.

JavaScript
const it = [1, 2, 3, 4, 5].values();

const firstThree = it.take(3);

console.log(firstThree.toArray());   // [1, 2, 3]
CallWhat it does
iterator.take(limit)Yield at most limit values from the front of the iterator.
iterator.take(n).toArray()Take the first n values into an array.
[1, 2, 3].values().take(2)Start from an array iterator with .values().
iterator.filter(fn).take(n)Filter first, then keep only the first n matches.

An Iterator helper (Baseline Newly available) on Iterator.prototype. No import required. Feature-detect before use in older engines. Siblings: Iterator.concat(), Iterator.from(), Iterator.zip(), Iterator.zipKeyed(), chunks(), drop(), every(), filter(), find(), flatMap(), forEach(), includes(), join(), map(), reduce(), some(), toArray(), windows(), [Symbol.dispose](), [Symbol.iterator]().

Library declarations
JavaScript
// 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

ParameterDescription
limitRequired. A number saying how many values to yield at most. Use a non-negative integer such as 0, 1, or 3.

Return Value

Return ValueDescription
Iterator helperA 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().

JavaScript
const nums = [1, 2, 3, 4, 5].values();
const firstThree = nums.take(3);

console.log(firstThree.toArray());
Try It Yourself

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

  1. Start with five numbers. The iterator can yield 1 through 5.
  2. Limit to three. take(3) allows only the first three values.
  3. 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);
Try It Yourself

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

  1. Keep the evens. The filter would allow 2, 4, and 6.
  2. Stop after two. take(2) yields only 2 and 4.
  3. 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);
}
Try It Yourself

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

  1. Yield four colors. The generator can produce red, green, blue, and yellow.
  2. Keep only two. take(2) stops after the first two yields.
  3. Print as you go. for...of shows red then green.

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.

2025 Standard since
Google Chrome 122+ · Desktop & Mobile
Full support
Microsoft Edge 122+ · Chromium based
Full support
Mozilla Firefox 131+ · Desktop & Mobile
Full support
Apple Safari 18.4+ · macOS & iOS
Full support
Opera 108+ · Chromium based
Full support
Samsung Internet 26+ · Android
Supported
Android WebView 122+ · Chromium based
Supported
Node.js 22+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No 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.

Next: toArray()

Learn how to collect every remaining value from an iterator into a normal array.

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

14 people found this page helpful