Run details:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:131.0) Gecko/20100101 Firefox/131.0
Firefox 131
Ubuntu
Desktop
2 months ago
Test name Executions per second
Array.from 653529.2 Ops/sec
Array.slice 1341255.4 Ops/sec
Array.push 1289353.4 Ops/sec
Array[index] 1355816.9 Ops/sec
Array spread 797671.4 Ops/sec
Tests:
  • Array.from

    AخA
     
    const elements = document.all;
    const arr = Array.from(elements);
  • Array.slice

     
    const elements = document.all;
    const arr = Array.prototype.slice.call(elements, 0);
  • Array.push

     
    const elements = document.all;
    const amount = elements.length;
    const arr = [];
    for (let i = 0; i < amount; i += 1) arr.push(elements[i]);
  • Array[index]

     
    const elements = document.all;
    const amount = elements.length;
    const arr = Array(amount);
    for (let i = 0; i < amount; i += 1) arr[i] = elements[i];
  • Array spread

     
    const elements = document.all;
    const arr = [...elements];