Array.from vs Array.prototype.map

前端 未结 4 1109
耶瑟儿~
耶瑟儿~ 2021-02-18 15:27

So what is the difference between this two functions?

They both create new Array object. Only difference I found so far is that Array.from supp

4条回答
  •  不要未来只要你来
    2021-02-18 15:40

    The purpose of Array.from() is to take a non-array (but array-like) object and make a copy of it into an actual array. This then allows you to use ALL array methods on the copy including things beyond just iterating it such as .splice(), .sort(), .push(), .pop(), etc... which is obviously much more capable than just make .map() work with array-like things.

提交回复
热议问题