I know that there were a lot of topics like this. And I know the basics: .forEach()
operates on original array and .map()
on the new one.
I
forEach() :
return value : undefined
originalArray : not modified after the method call
newArray is not created after the end of method call.
map() :
return value : new Array populated with the results of calling a provided function on every element in the calling array
originalArray : not modified after the method call
newArray is created after the end of method call.
Since map builds a new array, using it when you aren't using the
returned array is an anti-pattern; use forEach or for-of instead.