Array.from()使用场景

1.获取的元素DOM集合

<ul>
  <li>1111</li>
  <li>2222</li>
</ul>

2.arguments(类数组)

function show (){
  let args = Array.from(arguments)
  console.log(args)
}
show(1,2,3,4,5)

3.把字符串转化成数组

let str = 'string'
let arr = Array.from(str)
console.log(arr)

4.json,必须有长度才可以转

let json ={
  0:'aaa',
  1:'bbb',
  2:'ccc',
  length:3
}
let arr = Array.from(json)
console.log(arr)

posted @ 2021-10-01 13:25  果果1024  阅读(107)  评论(0)    收藏  举报