类数组的判断
let a=类数组
let b=数组
// 第一种方式 instanceof
console.log(a.constructor === Array); //false
console.log(b.constructor === Array); //true
// 第二种方式
console.log(a instanceof Array); //false
console.log(b instanceof Array); //true
// 第三种方式
console.log(Object.prototype.toString.call(a) === "[object Array]"); //fasle
console.log(Object.prototype.toString.call(b) === "[object Array]"); //true
// 使用ES5提供的方法
console.log(Array.isArray(a)); //false
console.log(Array.isArray(b)); //true
类数组转数组
let a=类数组
// 第一种方式
Array.prototype.slice.call(a) //返回一个数组
// 第二种方式
[...a] //返回一个数组
// 第三种方式
Array.from(a) //返回一个数组