map() takes a function as argument which will run on all elements on the array (getting a transformed value), and then return a new array with all transformed values.
If we run the following array through .map(x => x + 1) we get:
.map(x => x + 1)
[1, 2, 3]
| | |
v v v
[2, 3, 4]
forEach() will just iterate on the array. Its return value is undefined.
Neither function will mutate the original array.
Great explanations and examples. Thanks again
We're a place where coders share, stay up-to-date and grow their careers.
We strive for transparency and don't collect excess data.