Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15
Safari 17
Mac OS X 10.15.7
Desktop
one year ago
Test name Executions per second
Array.prototype.slice 172210.7 Ops/sec
spread operator 107884.9 Ops/sec
Push operation 29459.6 Ops/sec
Script Preparation code:
AخA
 
var arr = Array.from({length: 10000}, () => Math.random())
Tests:
  • Array.prototype.slice

     
    var other =  arr.slice();
  • spread operator

     
    var other = [ ...arr ]
  • Push operation

     
    var other = []
    arr.forEach(el => other.push(el))