Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
for...of 명령문은 반복가능한 객체 (Array, Map, Set, String, TypedArray, arguments 객체 등을 포함)에 대해서 반복하고 각 개별 속성값에 대해 실행되는 문이 있는 사용자 정의 반복 후크를 호출하는 루프를 생성합니다.
각 반복에 서로 다른 속성값이 variable에 할당됩니다.
iterable반복되는 열거가능(enumerable)한 속성이 있는 객체.
let 대신 const도 사용할 수 있습니다, 블록 내부 변수를 수정하지 않는 경우.
NodeList 같은 DOM 컬렉션에 대해 반복: 다음 예는 article의 직계 자손인 paragraph에 read 클래스를 추가합니다:
생성기에 대해서도 반복할 수 있습니다:
iterable 프로토콜을 명시해서 구현하는 객체에 대해서도 반복할 수 있습니다:
for...in 루프는 객체의 모든 열거가능한 속성에 대해 반복합니다.
for...of 구문은 컬렉션 전용입니다. 모든 객체보다는, [Symbol.iterator] 속성이 있는 모든 컬렉션 요소에 대해 이 방식으로 반복합니다.
다음 예는 for...of 루프와 for...in 루프의 차이를 보입니다.
| ECMAScript® 2027 Language Specification # sec-for-in-and-for-of-statements |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 2월 11일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.