![]() |
VOOZH | about |
Underscore.js is a lightweight JavaScript library and not a complete framework that was written by Jeremy Ashkenas. It provides utility functions for a variety of use cases in our day-to-day common programming tasks. Underscore.js provides a lot of features that make our task easy to work with objects. It can be used directly inside a browser and also with Node.js.
With just under six kilobytes in size, this library provides us with many useful JavaScript functions for making our lives easier. There are hundreds of different functions available that support both our workaday functional helpers such as the map and filter functions, as well as more specialized ones such as JavaScript templating, function binding, deep equality testing, creating quick indexes, and many more. Underscore.js functions fall under four major categories which are functions that can be used for manipulating arrays, functions that can be used for manipulating objects, functions that can be used for manipulating both arrays as well as objects, and functions that can be used for manipulating other functions themselves.
We can use Underscore.js directly inside the browser and also with node.js. We will discuss both of these methods.
Include the following CDN link inside your code in order to run the underscore.js code inside the browser.
https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.13.6/underscore-min.js
We can install it with npm. Make sure that you have Node.js and npm installed.
npm install underscoreYou can also install with yarn
yarn install underscoreNow let's understand the working of code through an example.