One of the great things about Lodash is that it’s broken up into individual modules. You can choose to load the full build if you really need it, but if not, choosing to load only the modules you need (such as chain.js or forEach.js) will significantly cut down on your code base.
(Above: individual modules of Lodash available on the jsDelivr CDN)
The Lodash library is broken up into 13 main areas, with methods for an Array, Collection, Date, Function, Lang, Math, Number, Object and other areas. All methods start with an underscore _ (hence the library names “Underscore” / “Lodash”) followed by a period then a descriptor of what it does.
Below are just a few examples of useful methods available in the library:
_.chunk will take an array passed in as an argument and evenly “chunk” it into smaller groups, the length of which is given as a second argument. If the array isn’t evenly divisible, the last grouping will be the remaining leftover values:
_.chunk([2000, 2001, 2002, 2003, 2004, 2005], 2);
// returns [[2000, 2001], [2002, 2003], [2004, 2005]]
_.chunk([2000, 2001, 2002, 2003, 2004, 2005], 5);
// returns [[2000, 2001, 2002, 2003, 2004], ]
_.tail will return all but the first value of an array passed to it:
_.tail([2000, 2001, 2002, 2003]);
// returns [2001, 2002, 2003]
._flattenDeep recursively “flattens” or removes all layers of nested arrays within an array:
_.flattenDeep([a, b, [c, d, [e, f]], g]);
// returns [a, b, c, d, e, f, g]
Why You Should Use Lodash