• Skip to main content
  • Skip to search
  • Skip to select language
HTML

Structure of content on the web

  • Web APIs

    Interfaces for building web applications

  • Learn
    • CSS

      Learn to style content using CSS

    • Overview

      A customized MDN experience

    • FAQ

      Frequently asked questions about MDN Plus

  • HTTP Observatory

    Scan a website for free

  • JavaScript
  • Set.prototype[Symbol.iterator]()
      • Deutsch
      • Español
      • Français
      • 日本語
      • 한국어
      • 中文 (简体)

    In this article

    • Try it
    • Syntax
    • Examples
    • Specifications
    • Browser compatibility
    • See also
    1. Set[Symbol.species]
  • Instance methods
    1. Set.prototype.difference()
    2. Set.prototype.intersection()
    3. Set.prototype.keys()
    4. Set.prototype[Symbol.iterator]()
  • Instance properties
    1. Function.prototype.bind()
    2. Function: displayName Non-standard
    3. Function.prototype.arguments Non-standard Deprecated
    4. Function.prototype.caller Non-standard Deprecated
  • Instance methods
    1. Object.prototype.__defineGetter__() Deprecated
    2. Object.prototype.__defineSetter__() Deprecated
    3. Object.prototype.__lookupGetter__() Deprecated
    4. Object.prototype.__lookupSetter__() Deprecated
    5. Object.prototype.toLocaleString()
    6. Object.prototype.__proto__ Deprecated
    7. iterable protocol and allows Set objects to be consumed by most syntaxes expecting iterables, such as the set iterator object that yields the values of the set in insertion order.

      The initial value of this property is the same function object as the initial value of the Set.prototype.values property.

  • Try it

    const set1 = new Set();
    
    set1.add(42);
    set1.add("forty two");
    
    const iterator1 = set1[Symbol.iterator]();
    
    console.log(iterator1.next().value);
    / Expected output: 42
    
    console.log(iterator1.next().value);
    / Expected output: "forty two"
    

    Syntax

    js
    set[Symbol.iterator]()
    

    Parameters

    None.

    Return value

    The same return value as iterable, and iterating syntaxes like the for...of loop automatically call this method to obtain the iterator to loop over.

    js
    const mySet = new Set();
    mySet.add("0");
    mySet.add(1);
    mySet.add({});
    
    for (const v of mySet) {
      console.log(v);
    }
    

    Manually hand-rolling the iterator

    You may still manually call the next() method of the returned iterator object to achieve maximum control over the iteration process.

    js
    const mySet = new Set();
    mySet.add("0");
    mySet.add(1);
    mySet.add({});
    
    const setIter = mySet[Symbol.iterator]();
    
    console.log(setIter.next().value); / "0"
    console.log(setIter.next().value); / 1
    console.log(setIter.next().value); / {}
    

    Specifications

    Specification
    ECMAScript® 2026 Language Specification
    # sec-set.prototype-%symbol.iterator%

    Browser compatibility

    See also

    • Set
    • Set.prototype.entries()
    • Set.prototype.keys()
    • Set.prototype.values()
    • Symbol.iterator
    • Iteration protocols

    Help improve MDN

    Follow Lee on X/Twitter - Father, Husband, Serial builder creating AI, crypto, games & web tools. We are friends :) AI Will Come To Life!

    Check out: eBank.nz (Art Generator) | Netwrck.com (AI Tools) | Text-Generator.io (AI API) | BitBank.nz (Crypto AI) | ReadingTime (Kids Reading) | RewordGame | BigMultiplayerChess | WebFiddle | How.nz | Helix AI Assistant