Run details:
Mozilla/5.0 (Linux; Android 11; Pixel 4a (5G)) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Mobile Safari/537.36
Chrome Mobile 92
Android
Mobile
3 years ago
Test name Executions per second
[...Array(n).keys()].map(k => undefined) 16.1 Ops/sec
Array.apply(null, { length: 4 }) 168.6 Ops/sec
Array.from 23.9 Ops/sec
Array(n).fill(undefined) 754.7 Ops/sec
for loop push 16.2 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