类数组
类数组
类似于数组,它有和数组一样的下标,length,[],但是不能使用数组的方法
比如:一组元素、arguments
类数组转数组
目的就是为了使用数组的方法
(写字母 Array 和 简写 [] 是一样的)
- Array.from(arguments)
- Array.prototype.slice.call(arguments)
- [].slice.call(arguments)
- [].concat.apply([],arguments)
- [...li]
const li = document.querySelectorAll("li");
console.log(li);//类数组:有length,有下标。不能用数组的方法,不能修改length
console.log(Array.from(li));
console.log(Array.prototype.slice.call(li));
console.log([].slice.call(li));
console.log([].concat.apply([],li));
let lis = [...li];//ES6中的扩展运算符
console.log(lis);