Javascript 为什么arguments是一个类数组?用什么方法遍历类数组?
因为arguments是一个对象,他的属性是从0依次增大的数字,并且不能使用数组的方法,所以它是一个类数组。
(1)用call()或apply()方法先将类数组转换成真正的数组
Array.prototype.forEach.call(arguments,a=>console.log(a))
(2)用Array.from()方法将数组转换成真正的数组
const arr = Array.from(arguments);
arr.forEach()
(3)利用扩展运算符转换为真数组
[…arguments].forEach()
