In the task I mentioned above for reversing strings and putting them in a new array, I agree that forEach is a good approach.
I personally would still prefer map() over forEach() because
we don't have to push element to newArray manually
since map() returns an array. we can do further processing on array like filtering and sorting right there after running map() without ever need to manipulate newArray.
In the task I mentioned above for reversing strings and putting them in a new array, I agree that
forEach
is a good approach.I personally would still prefer
map()
overforEach()
becausenewArray
manuallymap()
returns an array. we can do further processing on array like filtering and sorting right there after runningmap()
without ever need to manipulatenewArray
.For example.
totally agree!