Test name | Executions per second |
---|---|
Object.fromEntries | 735.2 Ops/sec |
Reduce (reuse object) | 979.6 Ops/sec |
Reduce (creating temporary objects) | 0.2 Ops/sec |
var data = { Array.from(Array(10000).keys()) };
Object.fromEntries(Object.entries(data).filter((key, value) => value % 2 === 0));
Object.entries(data).reduce((acc, [key, value]) => {
if (value % 2 === 0) {
acc[key] = value;
}
return acc;
}, {});
Object.entries(data).reduce((acc, [k, v]) => ({
acc,
v % 2 === 0 && {[k]: v}) (
}), {});