| name | lodash-4-18-1 |
| description | Complete toolkit for Lodash 4.18 utility library providing 300+ helper functions for arrays, collections, objects, strings, numbers, dates, and functions. Use when building JavaScript applications requiring robust data manipulation, functional programming patterns, type checking, or cross-platform compatibility without native ES6+ features. |
Lodash 4.18
Overview
Lodash is a JavaScript utility library delivering consistency, modularity, performance, and extras. It provides over 300 helper functions organized into 11 categories: Array, Collection, Date, Function, Lang, Math, Number, Object, Seq, String, and Util. Lodash makes JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, and more.
The library is released under the MIT license and supports modern environments including Node.js 4+, Bun 1.0+, and the latest Chromium, Firefox, WebKit, and Edge browsers with best-effort support for Chrome 74+, Firefox 66+, IE 11, Edge 18, and Safari 11+.
When to Use
- Iterating arrays, objects, and strings with consistent cross-browser behavior
- Manipulating and testing values (type checking, deep equality, cloning)
- Creating composite functions (currying, partial application, debouncing, throttling)
- Building functional programming pipelines with
lodash/fp
- Data transformation tasks: sorting, grouping, partitioning, mapping
- Working with deeply nested objects via path-based access (
_.get, _.set)
- Needing reliable polyfills for older browser environments
- Reducing boilerplate in data processing and ETL workflows
Core Concepts
Module Loading
Lodash supports multiple import strategies for tree-shaking and bundle optimization:
var _ = require('lodash');
var _ = require('lodash/core');
var fp = require('lodash/fp');
var array = require('lodash/array');
var object = require('lodash/object');
var debounce = require('lodash/debounce');
var get = require('lodash/get');
In a browser:
<script src="lodash.js"></script>
<script src="https://cdn.jsdelivr.net/npm/lodash@4.18.1/lodash.min.js"></script>
Iteratee Shorthands
Most Lodash methods accept an iteratee parameter that supports three shorthand forms, reducing boilerplate:
Property shorthand — passes a property name to create a function that returns the value of that property:
_.map(users, 'name');
Matches shorthand — passes a source object to create a function that performs a partial deep comparison:
_.filter(users, { 'active': true, 'role': 'admin' });
MatchesProperty shorthand — passes a [key, srcValue] pair to create a function that checks if an element's property matches the source value:
_.find(users, ['active', false]);
Lazy Evaluation
Lodash chains support lazy evaluation — when possible, method calls are compiled into a single optimized function. This avoids creating intermediate arrays and dramatically improves performance on large collections:
_.map(_.filter(largeArray, predicate), transform);
_(largeArray).filter(predicate).map(transform).value();
Lazy evaluation works with: chunk, compact, drop, dropRight, dropRightWhile, dropWhile, filter, first, flatMap, flatten, flattenDeep, flattenDepth, map, nth, reverse, sample, take, takeRight, takeRightWhile, takeWhile, uniq, uniqBy, uniqWith.
Build Options
- Full build — all 300+ methods, ~24KB gzipped
- Core build — 63 essential methods, ~4KB gzipped, Backbone.js compatible, no lazy evaluation or placeholder support
- FP build — immutable auto-curried iteratee-first data-last variants of all methods
- Strict build — throws errors when attempting to overwrite read-only properties in
_.assign, _.bindAll, _.defaults
- Custom builds — via lodash-cli, cherry-pick only needed methods
Immutability Patterns
Lodash distinguishes between mutating and non-mutating operations:
_.pull(array, 'a', 'c');
_.remove(array, predicate);
_.reverse(array);
_.without(array, 'a', 'c');
_.filter(array, predicate);
_.drop(array, n);
Usage Examples
Deep object access with safe defaults
_.get(user, 'profile.address.city', 'Unknown');
Function composition
var enhance = _.flow(_.trim, _.capitalize, _.escape);
enhance(' hello world ');
Debounced search input
var debouncedSearch = _.debounce(function(query) {
fetchResults(query);
}, 300, { 'leading': false, 'trailing': true });
Grouping and counting
var byStatus = _.groupBy(users, 'status');
var statusCounts = _.countBy(users, 'status');
Deep merge with custom conflict resolution
var result = _.mergeWith(
defaults,
overrides,
function(objValue, srcValue) {
if (Array.isArray(objValue)) {
return srcValue;
}
}
);
Advanced Topics
Array Methods: Filtering, sorting, slicing, flattening, set operations → Array Methods
Collection Methods: Iteration, grouping, partitioning, reduction → Collection Methods
Function Methods: Currying, debouncing, throttling, partial application → Function Methods
Object Methods: Property access, merging, picking, transforming → Object Methods
String Methods: Formatting, escaping, case conversion, templating → String Methods
Lang Methods: Type checking, equality comparison, cloning → Lang Methods
Math Methods: Aggregation, clamping, random numbers → Math Methods
Util Methods: Identity functions, iteration helpers, mixins → Util Methods
Chaining and FP: Lazy evaluation chains, lodash/fp functional style → Chaining and FP