what use does the javascript forEach method have (that map can't do)?

前端 未结 8 1442
小鲜肉
小鲜肉 2020-12-04 07:24

The only difference I see in map and foreach is that map is returning an array and forEach is not. However, I don\'t even understand the last line

8条回答
  •  渐次进展
    2020-12-04 07:44

    You can use map as though it were forEach.

    It will do more than it has to, however.

    scope can be an arbitrary object; it's by no means necessarily this.

    As for whether there are real uses for map and forEach, as well to ask if there are real uses for for or while loops.

提交回复
热议问题