[removed] Difference between .forEach() and .map()

后端 未结 12 1897
余生分开走
余生分开走 2020-11-22 15:19

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

12条回答
  •  无人及你
    2020-11-22 16:03

    The main difference that you need to know is .map() returns a new array while .forEach() doesn't. That is why you see that difference in the output. .forEach() just operates on every value in the array.

    Read up:

    • Array.prototype.forEach() - JavaScript | MDN
    • Array.prototype.map() - JavaScript | MDN

    You might also want to check out: - Array.prototype.every() - JavaScript | MDN

提交回复
热议问题