<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>扩展运算符应用</title> </head> <body> <div>1</div> <div>2</div> <div>3</div> <div>4</div> </body> <script> /*利用扩展运算符将伪数组转成真数组*/ // var oDivs= document.getElementsByTagName('div'); // console.log(oDivs) // console.log( oDivs instanceof Array) //判断是不是真数组 // // let arr =[...oDivs]; // console.log(arr) // console.log(arr instanceof Array) let arrLike = { "0" : 1, "1": 3, '2' :4, "length" :3 } //from 将伪数组转成数组并对数据进一步处理 const _arr = Array.from(arrLike,(item) =>{ return item*2 }) console.log(_arr) </script> </html>
运行结果