JavaScript Iterator join() Method

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

Definition

iterator.join(separator) reads every value from the iterator, turns each one into text, and glues them together into one string. If you omit the separator, a comma is used between values.

The method consumes the whole iterator. It is not lazy: it must finish reading before it can return the final string. An empty iterator joins to an empty string.

Remember
iterator.join()
iterator.join(separator)

default separator → ","
empty iterator    → ""
null / undefined  → treated as ""

Returns a string. Consumes the whole iterator.

Syntax

Call it on an iterator. Pass an optional separator string, or use the default comma.

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

console.log(nums.join("-"));   // "1-2-3-4-5"
CallWhat it does
iterator.join()Join all values with a comma between them.
iterator.join(separator)Join all values with your own separator string.
[1, 2, 3].values().join(" / ")Build a readable string from an array iterator.

A newer JavaScript Iterator helper method on every iterator, from Iterator.prototype. No import required. Feature-detect before use. Siblings: Iterator.concat(), Iterator.from(), Iterator.zip(), Iterator.zipKeyed(), chunks(), drop(), every(), filter(), find(), flatMap(), forEach(), includes(), map(), reduce(), some(), take(), toArray(), windows(), [Symbol.dispose](), [Symbol.iterator]().

Library declarations
JavaScript
// Newer Iterator helper
Iterator.prototype.join()
Iterator.prototype.join(separator)

// separator : optional string (default ",")
// returns   : string

Parameters

ParameterDescription
separatorOptional. Text placed between each pair of values. If omitted, "," is used. Pass "" to stick values together with nothing in between.

Return Value

Return ValueDescription
stringOne string made from every yielded value. null and undefined become empty pieces (not the words "null" or "undefined"). An empty iterator returns "".

JavaScript Examples

Example 1 — Join Values With the Default Comma

Turn 1 through 5 into one comma-separated string.

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

console.log(text);
Try It Yourself

The Try It page first checks that iterator.join() 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. Make an iterator. [1, 2, 3, 4, 5].values() yields each number.
  2. Call join(). With no argument, the separator is a comma.
  3. Get one string. The result is "1,2,3,4,5".

Example 2 — Join Values With a Custom Separator

Use a dash between numbers for a clearer string.

JavaScript
const nums = [1, 2, 3, 4, 5].values();
const text = nums.join(" - ");

console.log(text);
Try It Yourself

The Try It page first checks that iterator.join() 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. Pass a separator. " - " is placed between each pair of values.
  2. Values become text. Each number is converted to a string piece.
  3. Read the result. The full string is "1 - 2 - 3 - 4 - 5".

Example 3 — See Empty, null, and undefined Pieces

Join an iterator that includes null and undefined, and see how they become empty text.

JavaScript
const items = ["a", null, "b", undefined, "c"].values();
const text = items.join("|");

console.log(text);
console.log("Length: " + text.length);
Try It Yourself

The Try It page first checks that iterator.join() 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. Mixed values. The iterator yields text plus null and undefined.
  2. Empty pieces. null and undefined become empty strings, so you see double separators.
  3. Count characters. "a||b||c" has length 7.

Browser & Runtime Support

Iterator.prototype.join() is a newer Iterator helper. It is available in recent Chromium and Firefox builds; Safari support is still catching up. Feature-detect before you rely on it.

✓ Newer · Recent engines

iterator.join()

Supported in Chrome 153+, Edge 153+, Firefox 154+, Safari 27.3+, Opera 137+ and Node.js 24+. Internet Explorer never got it.

Recent Standard since
Google Chrome 153+ · Desktop & Mobile
Full support
Microsoft Edge 153+ · Chromium based
Full support
Mozilla Firefox 154+ · Desktop & Mobile
Full support
Apple Safari 27.3+ · macOS & iOS
Partial / recent
Opera 137+ · Chromium based
Full support
Samsung Internet Recent · Android
Supported
Android WebView 153+ · Chromium based
Supported
Node.js 24+ · Server runtime
Supported
Deno Recent versions · JavaScript runtime
Supported
Bun Recent versions · JavaScript runtime
Supported
Internet Explorer No native support
Not supported
iterator.join() Recent engines

Bottom line: Feature-detect with typeof Iterator.prototype.includes === "function" (or join). On older engines, convert with Array.from() and use the matching Array method.

Frequently Asked Questions

It reads every value from an iterator and returns one string with an optional separator between values. The default separator is a comma.
An empty string "". There are no values to glue together.
They become empty string pieces, not the words "null" or "undefined". That can create double separators in the result.
No in practice. join() must finish reading the whole iterator before it returns, so an infinite source never completes. Use take() first to limit how many values you join.
It is a newer helper. Feature-detect with typeof Iterator.prototype.join !== "function" before you rely on it in older browsers.

Next: map()

Learn how to transform each value from an iterator into a new value, lazily.

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

11 people found this page helpful