What is Underscore.js?
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.
 Underscore Tutorial
Why Underscore.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.
How to Install and use Underscore.js?
We can use Underscore.js directly inside the browser and also with node.js. We will discuss both of these methods.
Method 1: Using CDN Link
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
Method 2: Using nmp or yarn Package Manager
We can install it with npm. Make sure that you have Node.js and npm installed.
npm install underscore
You can also install with yarn
yarn install underscore
Now let’s understand the working of code through an example.
Features of Underscore.js
- Perform common operations of data like arrays, objects, JSON files, etc.
- Compatible with other JS libraries like jQuery to perform DOM operations.
- Contains function for data manipulation.
Learn more about Underscore.js
Underscore.js Collections Methods
Underscore.js Array Methods
Underscore.js Functions
Underscore.js Object Methods
Underscore.js Utility Methods
|