Files
2nd/10_Wiki/Dev/Topic_JavaScript/JavaScript_Iterables.md
T
Antigravity Agent 1cfd3bbb56 docs(10_Wiki): 위키 구조 정리 — 언어 튜토리얼 카테고리 폴더 제거 + 신규 자산 동기화
Topic_CSS/Topic_HTML/Topic_JavaScript/Topic_Prompt/Topic_Comfyui 등 기존 카테고리 폴더를 정리하고,
Topic_Graphic/Dev 등 신규 산출물과 Topics 내부 세션/메모리 기록을 동기화.
2026-07-05 00:10:59 +09:00

5.8 KiB

id, title, category, status, verification_status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, created_at, updated_at, review_reason, merge_history, tags, raw_sources, applied_in, github_commit
id title category status verification_status canonical_id aliases duplicate_of source_trust_level confidence_score created_at updated_at review_reason merge_history tags raw_sources applied_in github_commit
javascript-iterables JavaScript Iterables Frontend draft conceptual
JS iterables
iterable protocol
for...of
Symbol.iterator
iterable objects
B 0.88 2026-06-23 2026-06-23
javascript
js
web
frontend
w3schools
iterables
for-of
symbol-iterator
https://www.w3schools.com/js/js_iterables.asp

JavaScript Iterables

🎯 한 줄 통찰 (One-line insight)

Iterables are objects that can be looped over with the for...of statement; in JavaScript, Strings, Arrays, Typed Arrays, Sets, and Maps are all iterable because their prototypes carry a Symbol.iterator method. [S1]

🧠 핵심 개념 (Core concepts)

  • Iterable = loopable with for...of — an iterable is an object that can be iterated (looped) over with the for...of statement. [S1]
  • Built-in iterables — in JavaScript the following are iterables: Strings, Arrays, Typed Arrays, Sets, and Maps, because their prototypes have a Symbol.iterator method. [S1]
  • The iterator protocol — an object becomes an iterator by implementing a next() method that returns an object with value (the next value) and done (a boolean indicating completion). [S1]
  • Symbol.iterator is the hook — an object is made iterable by defining a Symbol.iterator method that returns an iterator. [S1]

🧩 추출된 패턴 (Extracted patterns)

  • for...of over any iterable — the same for (variable of iterable) loop works uniformly across strings, arrays, sets, and maps. [S1]
  • Custom iterable via Symbol.iterator — attach a Symbol.iterator function to a plain object so it can be used in for...of, giving you custom iteration logic for your own data structures. [S1]

📖 세부 내용 (Details)

Iterables Iterables are iterable objects (like Arrays). Iterables can be accessed with simple and efficient code. Iterables can be iterated over with for...of loops. [S1]

The for...of Loop The for...of statement loops through the elements of an iterable object. Its syntax is: [S1]

for (variable of iterable) {
  // code block to be executed
}

Iterating over a String You can use a for...of loop to iterate over the elements of a string: [S1]

const name = "W3Schools";

for (const x of name) {
  // code block to be executed
}

Iterating over an Array You can use a for...of loop to iterate over the elements of an array: [S1]

const letters = ["a","b","c"];

for (const x of letters) {
  // code block to be executed
}

Iterating over Sets and Maps for...of can also iterate over the elements of a Set and over the key/value pairs of a Map. [S1]

JavaScript Iterators The for...of loop relies on an iterator. The iterable must implement a method named Symbol.iterator. The Symbol.iterator method is called automatically by for...of. It returns an iterator object with a next() method. The next() method returns an object with a value property (the next value) and a done property (true or false). [S1]

Built-in Iterables In JavaScript the following are iterables: Strings, Arrays, Typed Arrays, Sets, and Maps. They are iterable because their prototype objects all have a Symbol.iterator method. [S1]

A User-Defined (Home-Made) Iterable You can make an object iterable by giving it a Symbol.iterator method. The example below creates an object that returns values 10, 20, 30, 40 ... and stops at 100: [S1]

myNumbers = {};

myNumbers[Symbol.iterator] = function() {
  let n = 0;
  done = false;
  return {
    next() {
      n += 10;
      if (n == 100) {done = true}
      return {value:n, done:done};
    }
  };
}

for (const num of myNumbers) {
  // Any Code Here
}

The next() method returns an object with two properties: value (the next value) and done (true when iteration is finished). [S1]

🛠️ 적용 사례 (Applied in summary)

The page's own snippets are the canonical applied examples — looping over the string "W3Schools", the array ["a","b","c"], and the home-made myNumbers iterable built with Symbol.iterator. No external project/commit applications found in the source.

💻 코드 패턴 (Code patterns)

Loop over any iterable (language: JavaScript):

for (const x of "W3Schools") {
  // code block to be executed
}

Make a plain object iterable:

myNumbers[Symbol.iterator] = function() {
  let n = 0;
  done = false;
  return {
    next() {
      n += 10;
      if (n == 100) {done = true}
      return {value:n, done:done};
    }
  };
}

⚖️ 모순 및 업데이트 (Contradictions & updates)

No contradictions found in the source.

검증 상태 및 신뢰도

  • 상태: draft
  • 검증 단계: conceptual (실제 적용 사례 발견 시 applied/validated로 승격 가능)
  • 출처 신뢰도: B (W3Schools — widely used educational reference, not a primary standards body)
  • 신뢰 점수: 0.88
  • 중복 검사 결과: 신규 생성 (New discovery)

🔗 지식 그래프 (Knowledge Graph)

📚 출처 (Sources)

📝 변경 이력 (Change history)

  • 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Iterables" page (Astra wiki-curation, P-Reinforce v3.1 format).