-
方法一:
Array.from(arguments)
-
方法二:
Array.prototype.slice.call(arguments)
slice 方法 不传递参数,默认返回值是全部数组
不能用 splice,返回值是删除的元素组成的数组
Array.prototype.slice.call(arguments,0,arguments.length);
-
方法三:for of
let res =[]; for(let item of arguments){ res.push(item); }
-
方法四:map 方法
Array.prototype.map.call(arguments,item=>item)
-
方法五:
[...arguments]
类数组转数组的五种方法
最新推荐文章于 2024-05-21 14:15:14 发布