Test name | Executions per second |
---|---|
fromEntries | 816.2 Ops/sec |
reducer | 2097.2 Ops/sec |
reducer with acc | 0.1 Ops/sec |
vartest = test = Array(10000)
.fill('')
.map((_, i) => ({ key: 'key' + i, value: 'value' + i }));
const result = Object.fromEntries(test.map(({ key, value }) => [key, value]));
const result2 = test.reduce((acc, { key, value }) => {
acc[key] = value;
return acc;
}, {});
const result3 = test.reduce((acc, { key, value }) => ({acc, [key]: value}), {});