Skip to content

类数组转化为数组

类数组具有 length 属性,但不具有数组原型上的方法。常见的类数组有 arguments、DOM操作方法返回的结果。

方法一:Array.from

js
Array.from(arguments);

方法二:Array.prototype.slice.call()

js
Array.prototype.slice.call(arguments)

方法三:扩展运算符

js
[...arguments]

方法四:利用concat

js
[].concat(arguments);

MIT Licensed | 沪ICP备20013265号-1 | Copyright © 2019-present AaronKong