본문 바로가기

언어(JS,TS)/JavaScript

JavaScript [궁금증 : .forEach, .map and .reduce vs for and for..of (속도나 효율비교)]

결론 return 값이 있으면 map을 사용하고 없으면 forEach를 사용하는 것이 기능적으로 조금더 좋아보이고

 

기능을 빼더라도 의미론적으로 좀 더 좋은 것 같음

 

 

https://leanylabs.com/blog/js-forEach-map-reduce-vs-for-for_of/

 

Performance of JavaScript .forEach, .map and .reduce vs for and for..of

Declarative programming is better 95% of the time. However, when performance matters, imperative style is the go-to solution.

leanylabs.com

 

https://medium.com/web-development-with-sumit/which-is-faster-in-javascript-map-vs-foreach-4d5a62daaaa6