将伪数组转换成为数组(JavaScript)

伪数组一般具有以下特点:
1、按索引方式存储数据;
2、具有length属性;
3、没有数组的push、shift、pop等方法;

不方便操作

三种方法

let arr = Array.from(arguments)

let arr = Array.prototype.slice.call(arguments);

let arr = [].slice.call(arguments)

function fn() {
    // let arr = Array.from(arguments)
    // let arr = Array.prototype.slice.call(arguments);
    let arr = [].slice.call(arguments)
    console.log(arr,arg instanceof Array);
}

猜你喜欢

转载自blog.csdn.net/weixin_45773503/article/details/107370441