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 |
<script src='https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.5/lodash.min.js'></script>
<script src=''>
</script>
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;
}
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']);
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']);
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']);
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']);
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']);