A:Array.prototype.forEach.call(item,function(el){console.log(el)})B:item.forEach(function(el){console.log(el)})or:item.forEach((el)=>{console.log(el)})想请问高手这两种写法的差别是什么?Array.prototype.forEach.call主要作用是什么?
2 回答

守着星空守着你
TA贡献1799条经验 获得超8个赞
第一种写法可用于类数组,比如{0:'a',1:'b',length:2}这类数据,有些选择器(比如:document.getElementsByTagName,document.querySelectorAll)或arguments等查出的数据都是类数组而不是真数组
添加回答
举报
0/150
提交
取消