_.chain([1, 2, 3, 4, 5]) .filter(function(num) { return num % 2 == 0; }) .map(function(num) { return num * num; }) .value();
var data = [ { name: 'Alice', age: 30 }, { name: 'Bob', age: 25 }, { name: 'Charlie', age: 35 }, { name: 'Dave', age: 30 } ]; _.chain(data) .groupBy('age') .mapValues(function(values) { return _.pluck(values, 'name'); }) .value();
{ '25': ['Bob'], '30': ['Alice', 'Dave'], '35': ['Charlie'] }Overall, Underscore.js is a package library designed for working with collections of data in JavaScript. The chaining functionality is a powerful way to combine multiple operations on those collections into a single expression, making it easier to write complex algorithms with minimal code.