HTML Preparation code:
x
 
1
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
2
<script src=''>
3
4
</script>
Script Preparation code:
 
var omit1 = (originalObj = {}, keysToOmit = []) =>
    Object.fromEntries(
        Object.entries(originalObj)
        .filter(([key]) => !keysToOmit.includes(key))
    )
var omit2 = new Function('obj', 'if (!obj) return {}; const { a, d, i, ...res } = obj; return res;');
var omit3 = (originalObject = {}, keysToOmit = []) => {  
    const clonedObject = { ...originalObject };              
    for (const path of keysToOmit) {                
      delete clonedObject[path]       
    }           
    return clonedObject;
}
function omit4(obj, keys) {
  var target = {};
  for (var i in obj) {
    if (keys.indexOf(i) >= 0) continue;
    if (!Object.prototype.hasOwnProperty.call(obj, i)) continue;
    target[i] = obj[i];
  }
  return target;
}
Tests:
  • Lodash

     
    const obj = {
      a:1,
      b:1,
      c:1,
      d:1,
      e:1,
      f:1,
      g:1,
      h:1,
      i:1,
    }
    const n = _.omit(obj, ['a','d','i']);
  • es omit

     
    const obj = {
      a:1,
      b:1,
      c:1,
      d:1,
      e:1,
      f:1,
      g:1,
      h:1,
      i:1,
    }
    const n = omit1(obj, ['a','d','i']);
  • compiled omit

     
    const obj = {
      a:1,
      b:1,
      c:1,
      d:1,
      e:1,
      f:1,
      g:1,
      h:1,
      i:1,
    }
    const n = omit2(obj, ['a','d','i']);
  • rest and delete omit

     
    const obj = {
      a:1,
      b:1,
      c:1,
      d:1,
      e:1,
      f:1,
      g:1,
      h:1,
      i:1,
    }
    const n = omit3(obj, ['a','d','i']);
  • babel

     
    const obj = {
      a:1,
      b:1,
      c:1,
      d:1,
      e:1,
      f:1,
      g:1,
      h:1,
      i:1,
    }
    const n = omit4(obj, ['a','d','i']);
Rendered benchmark preparation results:

Suite status: <idle, ready to run>

Previous results

Experimental features:

  • Test case name Result
    Lodash
    es omit
    compiled omit
    rest and delete omit
    babel

    Fastest: N/A

    Slowest: N/A

Latest run results:
Run details: (Test run date: 3 years ago)
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36
Chrome 93 on Mac OS X 10.15.7
View result in a separate tab
Test name Executions per second
Lodash 486282.3 Ops/sec
es omit 1320568.9 Ops/sec
compiled omit 974613.6 Ops/sec
rest and delete omit 2121455.5 Ops/sec
babel 787476.4 Ops/sec