对类数组对象的理解?如何转化为数组

161 阅读1分钟

和数组类似,拥有length属性,可以通过索引来访问或设置里面的元素,但是不能使用数组的方法。、

可以把类数组转换为数组。

Array.prototype.slice.call()

Array.from()

Array.prototype.splice.call(arrLike, 0);

// 创建一个类数组对象

let arrLike = {

0: 'name',

1: 'age',

2: 'job',

length: 3

}