-
[모던 자바스크립트] 루프프론트엔드 개발자가 될거야./js 2023. 4. 19. 15:18
- 배열에 대한 반복
1. 기존 for문
var fruits = ['apple', 'banana', 'orange']; for (var i=0; i < fruits.length; i++) { console.log(fruits[i]); } // apple // banana // orange
2. for of 문
const fruits = ['apple', 'banana', 'orange']; for (const fruit of fruits) { console.log(fruits[i]); } // apple // banana // orange
- 객체에 대한 반복
Object.key()로 객체의 모든 키를 가져온 후, 키에 대해 반복을 수행하면서 값에 접근하자!
const car = { maker : "BMW", color : "red", year : "2010", } for (const prop of Object.key(car)) { const value = car[prop]; console.log(prop, value); } // maker BMW // color red // year 2010
'프론트엔드 개발자가 될거야. > js' 카테고리의 다른 글
[모던 자바스크립트] 세트, 문자열 패딩 (0) 2023.04.19 [모던 자바스크립트] 템플릿 리터럴, 디스트럭처링 (1) 2023.04.18 [모던 자바스크립트] 함수 기본값 인수 (0) 2023.04.18 위코드 2주차 중간시험 리뷰 (0) 2022.07.01 [instagram 클론코딩] input 창에 엔터치거나 "게시"누르면 댓글 추가 구현하기 (0) 2022.06.29