Lodash in 2021: Necessary or Obsolete?

If you have a couple of years as a developer, you’ve probably used either Lodash or Underscore.js. These are two libraries that provide a bunch of utilities to manipulate data, particularly arrays and objects.

However, JavaScript now has many of the utilities these libraries offer. And now, the question is, are Lodash and Underscore still necessary? Or Am I adding unnecessary bloat into my project?

What You Already Can Do Without Lodash

This is a partial list of Lodash tasks that can now be replaced with vanilla JavaScript. If you use Lodash just for these utilities, you can replace it with Vanilla and remove the dependency.

Concatenate arrays, without mutating the original array:

Fill part of an array with a single value (mutates the array):

Flatten an array:

Create a duplicate-free version of the array:

Return an array with elements filtered out:

Check if an array includes a certain value:

But Sometimes You Do Need Lodash

Not every Lodash utility is available in Vanilla JavaScript. You can’t deep clone an object, for example. That’s why these libraries are far from obsolete. But if you’re loading the entire library just to use a couple of methods, that’s not the best way to use the library.

You can import just the functions you need. For example:

In fact, Lodash has an NPM package for every utility. You can just install the functions you need, like this:

However, if you decide to install specific utilities from Lodash, you have to import them differently:

Become a Better JavaScript Developer! My newsletter has easy, actionable steps to level up your JavaScript skills, right to your inbox. Click here to subscribe

Your JavaScript friend! I’ve been working for over a decade in JS, and I want to help you level up your skills