您的浏览器需要启用 JavaScript 才能正常访问此网站。
Hotline:15911225507
Long Xiao
Login
Home-All Questions-Javascript-Main Content

Javascript 为什么arguments是一个类数组?用什么方法遍历类数组?

LXLXJavascript3 years ago002.04K

因为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()
LX

LX

Lv1Rec2
Revitalize the WordPress experience with the power of Nuxt.js
From: Course-JavaScript 教程
119
Loading...
Share:
Long Xiao
No answers yet, be the first?
我要回答
Accepted answer rewards 100 points
Long Xiao
Please login first