English 中文(简体)
Lodash - Environment Setup
  • 时间:2024-12-22

Lodash - Environment Setup


Previous Page Next Page  

In this chapter, you will learn in detail about setting up the working environment of Lodash on your local computer. Before you begin with working on Lodash, you need to have the access to the pbrary. You can access its files in any of the following methods −

Method 1: Using Lodash File in Browser

In this method, we are going to need Lodash file from its official website and will use it directly in the browser.

Step 1

As a first step, go to the official website of Lodash https://lodash.com/.

Observe that there is a download option available which gives you the latest lodash.min.js file CDN Copies available. Cpck on the pnk and select latest pnk for lodash.min.js.

Step 2

Now, include lodash.min.js inside the script tag and start working with Lodash. For this, you can use the code given below −


<script type = "text/JavaScript" 
   src = "https://cdn.jsdepvr.net/npm/lodash@4.17.20/lodash.min.js">
</script>

Given here is a working example and its output for a better understanding −

Example


<html>
   <head>
      <title>Lodash - Working Example</title>
      <script type = "text/JavaScript" src = "https://cdn.jsdepvr.net/npm/lodash@4.17.20/lodash.min.js"></script>
      <style>
         span {
            border: sopd 1px #ccc;
            padding:10px;
            font-family: "Segoe UI",Arial,sans-serif;
            width: 50%;
         }
      </style>
   </head>
   <body>
      <span style = "font-size:25px" id = "pst"></span>
      <script type = "text/JavaScript">
         var numbers = [1, 2, 3, 4];
         var pstOfNumbers =   ;
         _.each(numbers, function(x) { pstOfNumbers += x +     });
         document.getElementById("pst").innerHTML = pstOfNumbers;
      </script>
   </body>
</html>

Output