Skip to content
Related Articles

Related Articles

Lodash Introduction

View Discussion
Improve Article
Save Article
  • Last Updated : 10 Dec, 2021

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. It provides us with various inbuilt functions and uses a functional programming approach that makes coding in JavaScript easier to understand because instead of writing repetitive functions, tasks can be accomplished with a single line of code. It also makes it easier to work with objects in javascript if they require a lot of manipulation to be done upon them.

Installation: It can be used directly using the CDN link or can be installed using npm or yarn.

Method 1: We can directly use the Lodash file in the browser. Go to the official documentation and copy the lodash.min.js file CDN link and paste this link inside the head section.

<script type = “text/JavaScript” src = “”></script>



<!DOCTYPE html>
<html lang="en">
    <meta name="viewport" content=
        "width=device-width, initial-scale=1.0">
    <script type="text/JavaScript" src=
        console.log(_.isNumber('GeeksforGeeks courses'));



Method 2: We can install it by using npm. Make sure that you have installed Node.js and npm.

npm install lodash

If you are using yarn then you can use the following command:

yarn install lodash

Now in order to use Lodash, you need to require the code file.

const _ = require("lodash");

Now let’s understand how to use Lodash with the help of the code example.

Example: In this example, we will find whether the given value parameter is a number or not using one of the inbuilt methods in the lodash _.isNumber() method.



// Requiring the lodash library  
const _ = require("lodash");  
// Use of _.isNumber() method 
console.log(_.isNumber('GeeksforGeeks courses')); 

Step to run the program: Save the above file with index.js and open the terminal and type the following command in order to compile and run the program.

node index.js



Advantages of Lodash:

  • It provides us with various inbuilt functions for collections, arrays, to manipulate objects and other utilities methods which we can use directly instead of writing them from scratch.
  • It keeps our code more short and clean that makes it easier to understand and modify later.
  • We have to remember Lodash functions and that makes out the task of coding much simpler.
  • It is easier to start and learn for tech newbies.
  • Instead of writing repetitive functions, tasks can be accomplished with a single line of code.

Disadvantages of Lodash:

  • The firstmost disadvantage of Lodash is speed. Lodash methods take more time to execute than normal JavaScript functions.
  • In JavaScript, we can chain many functions together as we want but in Lodash we can’t chain functions, we can only wrap them.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!