Home map 메소드 활용
Post
Cancel

map 메소드 활용


AS-IS

1
2
3
4
const cars = [];
for (const name of names) {
    cars.push(new Car(name));
}

TO-BE

map을 이용하여 간단한 반복문은 더욱 간결하고 가독성있게 표현할 수 있다.

1
const cars = names.map(name => new Car(name))
This post is licensed under CC BY 4.0 by the author.