Difference Between Foreach and Map in Javascript

Difference Between Foreach and Map in Javascript
Rating: 5 - 1 Votes

Difference Between Foreach and Map in Javascript

Foreach loop and map works pretty much the same.  The only difference between these two is the return.  In case of Foreach loop, you loop through all the items, modify them, but there is no return so you have store them in separate array inside the loop one by one. But in case of map, you loop through all items, modify them and it returns new array.

Examples are given below of Foreach and Map respectively: