Replacing lodash omit using object destructuring and the spread syntax

William Infante
Nerd For Tech
Published in
1 min readMar 2, 2021

--

Quick alternative to your handy omit

Photo by Kunj Parekh on Unsplash

_.omit() is the oh so handy function that lets you create an object that "exclude" properties from an object instead of explicity "including" all the other properties. But it is now being deprecated in Lodash 5 and probably for the better. For deep dive on the reason why it's being removed, I would suggest Dempsey's article.

Here’s a summary: performance, performance, performance. For example, the Semantic UI React team notice about 12000x improvement (yes, you counted those zeroes right, 12 thousand) for render times.

I’m listing here a quick alternative thanks to object destructuring and the spread syntax. Say we want to exclude apple from the list, using omit, we’ll probably have:

But even without adding libraries, we can use this instead:

I highly encourage you to review your code that uses omit from lodash. It may just save you the hassle of upgrading dependencies and may even boost your code performance.

--

--