伪数组怎么真数组
1、let newArr = Array.protype.slice.call(伪数组)
2、let newArr = Array.from(伪数组),ES6的新语法
3、let newArr = [...伪数组],使用扩展运算符,也是ES6的语法
<body>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
<script>
那些是伪数组
// arguments
// BOM的对象列表 document.querySelectorAll() document.getElementById() childNodes
// Array.from(lis) 把伪数组转换为真数组
const lis = document.querySelector("li"); const trueLi = Array.from(lis); //转换成真数组
console.log(trueLi); trueLi.push("1"); //可以使用数组的方法
</script>
</body>