_.omit
and its sibling _.pick
are popular utilities which apply filter-like functionality to objects. This lesson will demonstrate two techniques for building the functionality found in _.omit.
Object.assign
and removing unwanted keys with delete
for...in
and .includes
to manually copy keys into a result
objectNotes:
In modern JavaScript environments instead of Object.assign({}, obj)
you can also use { ...obj }
which will have the same effect of a shallow copy.
This lesson will not cover how to emulate _.omit
's support for taking either an array or multiple arguments for its keys, but our video on building _.pick from scratch covers one approach.