实现一个myOwnMap函数:输入:[1,2,3].myOwnMap((item,index)=>{returnitem*2})输出:[2,4,6]
2 回答

萧十郎
TA贡献1815条经验 获得超13个赞
数组的各种遍历方法本质其实就是reduce,所以可以利用reduce实现,简易实现版本:Array.prototype.myOwnMap=function(cb){returnthis.reduce(function(a,c,idx){a.push(cb(c,idx,this))returna},[])}
添加回答
举报
0/150
提交
取消