This content originally appeared on DEV Community and was authored by Piyush Panchal
Arrays are super useful and widely used data structures. It also has a ton of different functions which can make our work so much easier. The functions that many people get confused about is map()
and forEach()
and it's reasonable both do almost the same thing. I personally made this mistake so many times when I was a beginner. The similarity is- that they both run a function or a piece of code for each of the element of the array. But forEach()
does not return any new array. It just runs the code for the elements. map()
on the other hand returns a new array with the result. Hope this helped.
Thanks for reading.
This content originally appeared on DEV Community and was authored by Piyush Panchal
Piyush Panchal | Sciencx (2021-02-13T16:00:03+00:00) What’s the difference between map() and forEach() in JS?. Retrieved from https://www.scien.cx/2021/02/13/whats-the-difference-between-map-and-foreach-in-js/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.