伪数组就是一个含有length属性的json对象。它是按照索引的方式存储数据。它并不具有数组的一些方法,只能通过Array.prototype.slice转换为真正的数组,并且带有length属性的对象。
常见的伪数组
比如
var a = {0: 1, 1: 2, length: 2}
可以通过slice转为数组
Array.prototype.slice.call(a); // [1, 2]
Array.prototype.slice.apply(a); // [1, 2]
Array.prototype.slice.bind(a)(); // [1, 2]
//或者
[].slice.call(a); // [1, 2]
[].slice.apply(a); // [1, 2]
[].slice.bind(a)(); // [1, 2]
//或者
Array.from(a) // [1, 2]
©2018-2020 hongshali.com 版权所有 ICP证:闽ICP备18029655号-1