Run details:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36
Chrome 91
Mac OS X 10.14.6
Desktop
3 years ago
Test name Executions per second
[...Array(n).keys()].map(k => undefined) 56.8 Ops/sec
Array.apply(null, { length: 4 }) 402.0 Ops/sec
Array.from 52.7 Ops/sec
Array(n).fill(undefined) 2576.2 Ops/sec
for loop push 47.0 Ops/sec
Script Preparation code:
Tests:
  • [...Array(n).keys()].map(k => undefined)

  • Array.apply(null, { length: 4 })

  • Array.from

  • Array(n).fill(undefined)

  • for loop push