Extract value from path

Benchmark created by Milos Nedeljkovic on


Setup

const extractValue = (from, path) => {
    if (from == null) return from;
   
    let value = from;
    for (let i = 0; i < path.length; i++) {
      value = value[path[i]];
      if (value == null) return value;
    }
   
    return value;
  }

Test runner

Ready to run.

Testing in
TestOps/sec
Without array
extractValue({ a: { b: { c: 1 } } }, ['a', 'b', 'c'])
ready
With array
extractValue({ a: [{ c: 1 }] }, ['a', 0, 'c'])
ready

Revisions

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

  • Revision 1: published by Milos Nedeljkovic on