What is Underscore.js ?
Overview
Underscore.js is a popular JavaScript library that contains multiple utility and helper functions. Underscore.js can be used directly inside a browser and also with Node.js.
Note: To learn more about Underscore.js, click here.
Underscore.js includes multiple helper functions for the following:
- Arrays
- Functions
- Objects
- Collections
- Equality testing
- Function binding
Note: Underscore.js is licensed under the MIT License. You can find the repo of Underscore.js here.
Example
The code below demonstrates how to use Underscore.js.
Explanation
- Line 8: We include the Underscore.js library file from the CDN server.
- Line 10: We create an array,
numbers. - Line 12: We use the
firstmethod of the Underscore.js library to get the first element of the array. We get1as a result. - Line 13: We use the
lastmethod of the Underscore.js library to get the last element of the array. We get6as a result. - Line 14: We use the
minmethod of the Underscore.js library to get the minimum value element of the array. We get1as a result. - Line 15: We use the
shufflemethod of the Underscore.js library to get a shuffled copy of thenumbersarray.
Note: We can see all the functions available in Underscore.js here.