目标
实现类数组转化成数组
实例
链接地址
使用方法
const foo = document.querySelectorAll('.result') //链接地址输入控制台输入这行代码
const test = foo.slice() // 此行代码会报错,因为 foo 是一个类数组,不能使用数组的方法
解决
ES6 提供在数组中提供了Array.from 把类数组转化成数组
const foo = document.querySelectorAll('.result') //链接地址输入控制台输入这行代码
const nodes = Array.from(foo) // 此行代码是转化的关键代码
const test = foo.slice() // 此行代码会报错,因为 foo 是一个类数组,不能使用数组的方法
参考