Filter object entries by property

Benchmark created on


Setup

const ERROR = {
  EXDEV: {
    CODE: 'EXDEV',
    DESC: 'Invalid cross-device link (POSIX.1-2001).',
    ID: -18,
    IS_NODE: true,
    IS_POSIX: true,
  },
  EXFULL: {
    CODE: 'EXFULL',
    DESC: 'Exchange full.',
    ID: -54,
    IS_NODE: false,
    IS_POSIX: true,
  },
  UNKNOWN: {
    CODE: 'UNKNOWN',
    DESC: 'Unknown error.',
    ID: -4094,
    IS_NODE: true,
    IS_POSIX: false,
  },
};

Test runner

Ready to run.

Testing in
TestOps/sec
`Object.fromEntries`
Object.fromEntries(
  Object.entries(ERROR)
    .filter(([, value]) => value.IS_NODE)
);
ready
`Array.prototype.reduce`
Object.entries(ERROR)
  .filter(([, value]) => value.IS_NODE)
  .reduce((accum, [key, value]) => (
    { ...accum, [key]: value }
  ), {})
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.