UnderscoreJS

UnderscoreJs is a popular JS-based library that provides 100+ functions to facilitate web development.
It provides helper functions like map, filter, Invokes as well as function binding.

UnderscoreJs can be used directly inside a browser and also with node JS

Underscore comes with lots of features that ease your work with objects.

Features

  • Collections: Provide functions like each, map, reduce. Provides methods like groupBy, contentBy, max, min.
  • Arrays: Provides functions like iterate and process arrays like first, initial, last index of, intersection, difference, etc.
  • Functions: provide functions such as bind, delay, before, after, etc.
  • Objects: Provides functions to manipulate objects, map objects, and compare objects.
  • Utilities: Utility methods like noConflict, random, iterate, escape, etc.
  • Chaining: Provides chain value

UnderscoreJS Environment Setup

You can access its files in any of the following methods.

Method-1: Using underscoreJS file in browser

Step 1: Go to the official website of underscoreJS. There is a download option available that gives you the latest underscore- min.JS

Step 2: Include underscore-min.js inside the script tag and start working with underscoreJS.

Step 3: Copy the file underscore- min.js into a folder name this folder.

Step 4: Create an HTML file named underscore_hello.js

Step 5: Add html tag to the page. And in <head></head> tag add <script></script> tag. In tag src properties add the underscore- min.JS path.

Step 6: Include the below code in the body tag.
<body>

     <div style = “font-size:25px” id = “list”>

     </div>

     <script type = “text/JavaScript”>

        var hello = [“Hello”,”World!!!”];

        var helloworld = ”;

        _.each(hello, function(x) { helloworld += x + ‘ ‘ });

        document.getElementById(“list”).innerHTML = helloworld;

     </script>

  </body>

Leave a comment

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