Lodash in 2021: Necessary or Obsolete?

What You Already Can Do Without Lodash

let oneStooge = ["Moe"];
let twoStooges = ["Larry", "Curly"];
// Both create ["Moe", "Larry", "Curly"]
let threeStoogesLodash = _.concat(oneStooge, twoStooges);
let threeStoogesVanilla = [...oneStooge, ...twoStooges];
let someArray = [100, 99, 98, 97, 96, 95];
let someArrayCopy = [...someArray];
_.fill(someArray, 0, 2, 5); // [100, 99, 0, 0, 0, 95]
someArrayCopy.fill(0, 2, 5); // [100, 99, 0, 0, 0, 95]
let sonicCharacters = [
"Sonic",
"Tails",
"Knuckles",
["Amy Rose", "Shadow", "Dr. Eggman"]
];
// Both return:
// ["Sonic", "Tails", "Knuckles", "Amy Rose", "Shadow", "Dr. Eggman"]
let sonicCharactersFlatLodash = _.flatten(sonicCharacters);
let sonicCharactersFlatVanilla = sonicCharacters.flat();
let batmanLyrics = ["na", "na", "na", "na", "na", "Batman!"];// Both return ["na", "Batman"]
let batmanLyricsUniqueLodash = _.uniq(batmanLyrics);
let batmanLyricsUniqueVanilla = [...new Set(batmanLyrics)];
let countries = [
"United States",
"Belgium",
"Japan",
"China",
"South Korea"
];
// Both return ["Japan", "China", "South Korea"]
let asianCountriesLodash = _.filter(
countries,
country => country != "United States" && country != "Belgium"
);
let asianCountriesVanilla = countries.filter(
country => country != "United States" && country != "Belgium"
);
let frenchFlagColors = ["Blue", "White", "Red"];
// Both return false
let frenchFlagHasGreenLodash = _.include(frenchFlagColors, "Green");
let frenchFlagHasGreenVanilla = frenchFlagColors.include("Green");

But Sometimes You Do Need Lodash

// In ES6 module style:
import map from "lodash/map";
import cloneDeep from "lodash/cloneDeep";
// Or their CommonJS counterparts:
const map = require("lodash/map");
const cloneDeep = require("lodash/cloneDeep");
npm i lodash.clonedeep --save
// In ES6 module style:
import cloneDeep from "lodash.clonedeep";
// Or their CommonJS counterpart:
const cloneDeep = require("lodash.clonedeep");

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store