For
-
[JS] for in과 for of📙 Javascript 2024. 8. 27. 15:10
결론🙆♂️ for...of는 배열의 반복에서 사용 for...in은 객체의 반복에서 사용 for...of (Array)let arr = ["a", "b", "c"]for(item of arr) { console.log(arr); // a, b, c}용도: for...of는 이터러블 객체(iterable objects)를 순회할 때 사용합니다.동작 방식: 이터러블 객체의 값(value)들을 순회합니다. 이터러블 객체란? 🤷♂️반복(iteration) 할 수 있는 객체를 의미하며, 주로 배열(Array), 문자열(String), Map, Set, 등이 있습니다. for...in (Object)let obj = {"a": 1, "b": 2, "c": 3}for(item in obj) { conso..