Lodash: A modern JavaScript Utility library

Lodash is an open source(MIT licensed) modern javascript utility library to ease the programming tasks in a functional programming paradigm. The main goal of this library is modularity, performance and simplicity. This library handles the hard parts of javascript across various types of data such as Arrays, objects, strings, functions, date and so on. This project is inspired by UnderScore utility library.

The module methods are mainly used for

  • Iterating Arrays, Objects and Strings
  • Manipulating and testing values
  • Creating composite functions
  • Creating own mixins for Lodash

The major features of this library are,

  •    Modularity and consistency
  •    Enhances and compatible with ES6/7
  •    Compatible build available for IE8 and older
  •    Available in AMD, ES and CommonJS module formats

The library is available through both offline and online modes. The offline downloads of this library is available in both core build(~4kb gzipped) and full build(~24kb gzipped) variations. Whereas online resources are available through CDN.

To explore all the method examples of Lodash library, I created examples folder based on the official documentation and stored in the below github repository.

Github: https://github.com/sudheerj/awesome-javascript-technologies/tree/master/02-Lodash


It can be installed in both browser and node environments.

1.  Browser:  Attach script as either offline or online resource.

Offline resource:

Online resource:

Note: The bower support is removed in the latest version(v4) considering npm.

2.  Node module:  You can install through either npm or yarn package manager.



After installation, you can use the package using require as below ,  

If you are using specific methods then it is recommended to install and use those specific modules instead of downloading the entire library. For example, if you use times method in the project then it is recommended to install and use times module as below.

Why we need Utility functions

In almost all programming languages, we might heard about utility functions or classes. These utilities are helpful to reduce the repetitive work in an easy and performative approach. In earlier days and even in the current projects, we create utility folder in the project structure to deal with these repetitive and computed operations.

JavaScript utility libraries such as Underscore, Valentine, and wu are most used libraries compared to other libraries in the market. Initially Underscore library created a great impression in the utility libraries world. Thereafter, Lodash, a new library is inspired  and created a Underscore build as a replacement for UnderscoreJS with great enhancements. Currently Lodash is very active and defacto utility library in JS world.

The latest ECMAScript versions provided similar kind of methods by seeing the benefits of these methods. Even though ES6/E7 supported some of these methods natively in their browsers, lodash provides a huge set of methods considering each possible scenario in the real time development.

Modular methods:

The lodash modular methods are divided among Array,Collection, Function, Lang, String, Utils, Object, Number, Date, Seq  and Properties types. In the latest version(V4), there are around 320 methods existed. This blog cover one method from each major category to know the power of lodash library compared to plain JS implementation.

Lang- cloneDeep:

The language specific concepts and utility methods are categorized under Lang module. In this section, we will see how the deep cloning made easy with cloneDeep method. In plain JS development, we normally iterate each property type to clone the object fully. This process is quite cumbersome and difficult in practical usage. The implementation for this case is mentioned in this stack overflow thread(https://stackoverflow.com/questions/4459928/how-to-deep-clone-in-javascript). There is a simpler JS solution by parsing the stringified JS object. But lodash approach is  quite straight forward with single line of code.

JS code snippet: 

The iterative code approach is available here https://stackoverflow.com/questions/4459928/how-to-deep-clone-in-javascript and the simpler version of deep closing on the object which is not having any function as below.

Lodash code snippet:

Util – times: 

The various calculations/computations and common use-case scenarios are categorized under Util module. In this section, we will see how the iteration made simple with times method.  In plain JS development, we normally use basic for loop with nth iteration. This approach pollutes the scope with an additional variable.

JS code snippet:

Lodash code snippet:

Number- random:

The number specific computations or logic characteristics created under Number helper module. The random number generation with in the particular range is quite verbose in the native JS implementation. But lodash provides a method called random which accepts min and max boundaries as arguments. Moreover, the floating number is generated instead by enabling the third boolean argument.

JS code snippet: 

Lodash code snippet:

Collection – Map:

To iterate over collection of objects and array types, there is one group of methods which are categorized under Collection section.  The map method is very helpful while iterating over the collection with iteratee function invocation.  For example, iterating over collection of objects and filter the array with specific criteria involves more steps. But this can be easily solved with lodash library.

JS code snippet:

Lodash code snippet:

Array- remove:

The common use cases of arrays are simplified with some set of helper methods which are categorized under Array section. For example, the removal of few items from an array based on some conditions involves loops and conditional statements which returns the result. But lodash’s remove method  make it simple with single statement by returning the filtered array and deleted array.

JS code snippet:

Lodash code snippet:

Object- inverse:

In javascript everything is treated as object type. Due to this behavior, it involves many computations on object type.  Lodash provided a collection of object helper methods which are used to iterate and manipulate object properties. For example, in vanilla JS, we need to iterate the object to swap key and value pairs but it is simplified with inverse method.

JS code snippet:

Lodash snippet: 

Apart from the above types, lodash provides various other modules such as Functions, Math, Date, Methods, Properties and so on.  Please look at the github examples to cover all the helper methods.


The JavaScript acquired a rapid development in the recent days in both browser and node environments. Even though the latest ECMAScript specifications improved with native utility implementation, it is quite far away from the benefits of Lodash library and especially it’s functional programming approach.  Many projects using this library as direct and indirect dependency.  This library is recommended for every JS developer as a code helper and performance booster.

Leave a Reply

Your email address will not be published. Required fields are marked *