类数组

类数组

类似于数组,它有和数组一样的下标,length,[],但是不能使用数组的方法
比如:一组元素、arguments

类数组转数组

目的就是为了使用数组的方法
(写字母 Array 和 简写 [] 是一样的)

  1. Array.from(arguments)
  2. Array.prototype.slice.call(arguments)
  3. [].slice.call(arguments)
  4. [].concat.apply([],arguments)
  5. [...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);
posted @ 2018-11-07 21:51  真的想不出来  阅读(277)  评论(0编辑  收藏  举报