[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/Symbol.iterator [Back]  [Original]

Array.prototype[Symbol.iterator]() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array.prototype[Symbol.iterator]()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 9.

Array [Symbol.iterator]() , for...of . .

Array.prototype.values .

In this article

const array1 = ["a", "b", "c"];
const iterator1 = array1[Symbol.iterator]();

for (const value of iterator1) {
  console.log(value);
}

// Expected output: "a"
// Expected output: "b"
// Expected output: "c"

js
array[Symbol.iterator]()

.

Array.prototype.values() . .

for...of

. [Symbol.iterator] , for...of .

HTML

html
<ul id="letterResult"></ul>

JavaScript

js
const arr = ["a", "b", "c"];
const letterResult = document.getElementById("letterResult");
for (const letter of arr) {
  const li = document.createElement("li");
  li.textContent = letter;
  letterResult.appendChild(li);
}

next .

js
const arr = ["a", "b", "c", "d", "e"];
const arrIter = arr[Symbol.iterator]();
console.log(arrIter.next().value); // a
console.log(arrIter.next().value); // b
console.log(arrIter.next().value); // c
console.log(arrIter.next().value); // d
console.log(arrIter.next().value); // e

, . Array.prototype.values() .

js
function logIterable(it) {
  if (typeof it[Symbol.iterator] !== "function") {
    console.log(it, "is not iterable.");
    return;
  }
  for (const letter of it) {
    console.log(letter);
  }
}

// Array
logIterable(["a", "b", "c"]);
// a
// b
// c

// String
logIterable("abc");
// a
// b
// c

// Number
logIterable(123);
// 123   .

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype-%symbol.iterator%


Web Proxy Viewer  |  New URL  |  Original Page