What is underscore?
The underscore npm package is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects. It includes a wide range of functions for collections, arrays, functions, objects, and more.
What are underscore's main functionalities?
Collections
Iterates over a list of elements, yielding each in turn to an iteratee function.
_.each([1, 2, 3], function(num) { console.log(num); });
Arrays
Produces a duplicate-free version of the array.
_.uniq([1, 2, 1, 4, 1, 3]);
Functions
Curries a function so that it can be called with fewer arguments than it expects.
var greet = function(name) { return 'hi: ' + name; }; var greetCurried = _.curry(greet); greetCurried('Bob');
Objects
Copy all of the properties in the source objects over to the destination object.
_.extend({name: 'moe'}, {age: 50});
Utilities
Returns a random integer between the given min and max, inclusive.
_.random(0, 100);
Other packages similar to underscore
lodash
Lodash is a modern JavaScript utility library delivering modularity, performance, & extras. It is often considered as a drop-in replacement for Underscore with additional features and improved performance.
ramda
Ramda is a practical functional library for JavaScript programmers. It emphasizes a purer functional style, immutability, and function composition, making it quite different from Underscore in terms of API design and usage patterns.
lazy.js
Lazy.js is a functional utility library similar to Underscore and Lodash, but with a focus on lazy evaluation, which can lead to significant performance improvements for certain types of operations on large datasets.
__
/\ \ __
__ __ ___ _\ \ __ _ __ ____ ___ ___ _ __ __ /_\ ____
/\ /\ \ /' _ \ /'_ \ /'__
/\ / ,\ / \ / \/\ __\/'__
\ /\ \ /',\
\ \ _\ /\ /\ /\ \ \ /\ __/\ \ //_, \/\ \__//\ \ \ \ \ \//\ __/ __ \ \ \/\__,
\ _/\ _\ _\ ___,\ _\ _\/_/\ _\ _/\ _\ _/_\ \ \ /_/
// /////,_ /// // // //// // /////\ _\ //
\ _/
/__/
Underscore is a utility-belt library for JavaScript that provides
support for the usual functional suspects (each, map, reduce, filter...)
without extending any core JavaScript objects.
For Docs, License, Tests, and pre-packed downloads, see:
http://documentcloud.github.com/underscore/
Many thanks to our contributors:
https://github.com/documentcloud/underscore/contributors