[Javascript] forEach vs map (Array.prototype)
Interview Section은 FrontEnd Interview Question에 대한 QnA를 다룹니다. Q. Can you describe the main difference between the Array.forEach() loop and Array.map() methods and why you would pick one versus the other? A. 자바스크립트의 Array는 기본적으로 forEach와 map 등의 메서드를 프로토타입을 통해 제공합니다. 둘 다 Array안에 있는 Element들을 순회한다는 특징을 가지고 있지만, 둘은 결과물을 리턴하는 방식에서 차이를 보입니다. Array.prototype.map const arr = [1, 2, 3, 4, 5]; const mapAr..
2020.09.27