Most efficient way to convert an HTMLCollection to an Array

前端 未结 7 2252
闹比i
闹比i 2020-11-22 13:10

Is there a more efficient way to convert an HTMLCollection to an Array, other than iterating through the contents of said collection and manually pushing each item into an a

7条回答
  •  迷失自我
    2020-11-22 13:23

    not sure if this is the most efficient, but a concise ES6 syntax might be:

    let arry = [...htmlCollection] 
    

    Edit: Another one, from Chris_F comment:

    let arry = Array.from(htmlCollection)
    

提交回复
热议问题