Run details:
Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36 Edg/86.0.622.61
Chrome 86
Windows 7
Desktop
4 years ago
Test name Executions per second
[...Array(n).keys()].map(k => undefined) 20.0 Ops/sec
Array.apply(null, { length: 4 }) 113.1 Ops/sec
Array.from 18.9 Ops/sec
Array(n).fill(undefined) 1039.2 Ops/sec
for loop push 16.3 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