Test name | Executions per second |
---|---|
Map | 21.6 Ops/sec |
Array.apply + Fill | 0.0 Ops/sec |
While Loop | 16.2 Ops/sec |
For Loop | 16.2 Ops/sec |
New Array + Fill | 856.0 Ops/sec |
Array Literal With Length + Fill | 847.9 Ops/sec |
var length = 1000000;
var fillWith = 5;
const array = [Array(length)].map(() => fillWith);
const array = Array.apply([], { length }).fill(fillWith);
let index = length - 1;
const array = [];
while (index-- > 0) array[index] = fillWith;
const array = [];
for (let index = length - 1; index >= 0; index--) array[index] = fillWith;
const array = new Array(length).fill(fillWith);
const array = [];
array.length = length;
array.fill(fillWith);