HTML Preparation code:
x
 
1
2
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
Tests:
  • _.get

     
    var object = { 'a': [{ 'b': { 'c': 3 } }] };
     
    _.get(object, 'a[0].b.c');
  • native

     
    var object = { 'a': [{ 'b': { 'c': 3 } }] };
     
    /*
    const get = (obj, path, defaultValue) => {
      const result = String.prototype.split.call(path, /[,[\].]+?/)
        .filter(Boolean)
        .reduce((res, key) => (res !== null && res !== undefined) ? res[key] : res, obj);
      return (result === undefined || result === obj) ? defaultValue : result;
    }
     */
     const get = (obj, item, failure) => obj.item || failure;
    get(object, 'a[0].b.c');
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    _.get
    native

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 5 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
Chrome 78 on Mac OS X 10.15.2
View result in a separate tab
Test name Executions per second
_.get 1579572.0 Ops/sec
native 563340.6 Ops/sec