Lodash is a modern JavaScript utility library delivering modularity, performance & extras. It provides 296+ utility methods for common programming tasks using a functional programming approach, making JavaScript easier by taking the hassle out of working with arrays, numbers, objects, strings, etc.
Lodash is the most popular JavaScript utility library, providing a comprehensive set of 296+ functions for common programming tasks. Built with a focus on modularity, performance, and functional programming principles, Lodash simplifies complex operations on arrays, objects, strings, functions, and other data types.
Key Features:
/fp variant with auto-curried, iteratee-first methodsnpm install lodash// Full library import (UMD)
const _ = require('lodash');// ES6 imports
import _ from 'lodash';
import { map, filter, reduce } from 'lodash';// Individual method imports (recommended for bundle size)
const map = require('lodash/map');
const filter = require('lodash/filter');// Category imports
const array = require('lodash/array');
const object = require('lodash/object');// Functional programming variant
const fp = require('lodash/fp');Browser (UMD):
<script src="lodash.js"></script>
<script>
_.map([1, 2, 3], n => n * 2);
</script>const _ = require('lodash');
// Array operations
const numbers = [1, 2, 3, 4, 5, 6];
const evens = _.filter(numbers, n => n % 2 === 0);
const doubled = _.map(numbers, n => n * 2);
const chunks = _.chunk(numbers, 2); // [[1, 2], [3, 4], [5, 6]]
// Object manipulation
const users = [
{ name: 'Alice', age: 25, active: true },
{ name: 'Bob', age: 30, active: false },
{ name: 'Charlie', age: 35, active: true }
];
const activeUsers = _.filter(users, 'active');
const usersByAge = _.groupBy(users, 'age');
const names = _.map(users, 'name');
// String operations
const text = 'hello world';
const camelCase = _.camelCase(text); // 'helloWorld'
const kebabCase = _.kebabCase(text); // 'hello-world'
// Method chaining
const result = _(users)
.filter('active')
.map('name')
.sort()
.value(); // ['Alice', 'Charlie']Lodash is built around several key architectural patterns:
_.chain() and implicit chaining with _(value)/fp variants provide auto-curried, iteratee-first, and composition-friendly methodsComprehensive array manipulation utilities for chunking, flattening, filtering, and transforming arrays.
function chunk<T>(array: T[], size?: number): T[][];
function flatten<T>(array: T[] | T[][]): T[];
function uniq<T>(array: T[]): T[];
function intersection<T>(...arrays: T[][]): T[];Iteration and manipulation methods that work on arrays, objects, and other iterable collections.
function map<T, R>(collection: T[], iteratee: (value: T, index: number, array: T[]) => R): R[];
function filter<T>(collection: T[], predicate: (value: T, index: number, array: T[]) => boolean): T[];
function groupBy<T>(collection: T[], iteratee: string | ((value: T) => any)): { [key: string]: T[] };
function reduce<T, R>(collection: T[], iteratee: (accumulator: R, value: T, index: number, array: T[]) => R, initialValue?: R): R;Function composition, currying, debouncing, throttling, and other function manipulation utilities.
function debounce<T extends (...args: any[]) => any>(func: T, wait?: number, options?: DebounceOptions): T & { cancel(): void; flush(): ReturnType<T> };
function throttle<T extends (...args: any[]) => any>(func: T, wait?: number, options?: ThrottleOptions): T & { cancel(): void; flush(): ReturnType<T> };
function curry<T extends (...args: any[]) => any>(func: T, arity?: number): CurriedFunction<T>;
function memoize<T extends (...args: any[]) => any>(func: T, resolver?: (...args: any[]) => any): T & { cache: Map<any, any> };
interface DebounceOptions {
leading?: boolean;
maxWait?: number;
trailing?: boolean;
}
interface ThrottleOptions {
leading?: boolean;
trailing?: boolean;
}
type CurriedFunction<T> = T & {
(...args: any[]): any;
};Comprehensive type checking predicates and value conversion utilities for JavaScript types.
function isArray(value: any): value is any[];
function isObject(value: any): value is object;
function isString(value: any): value is string;
function isFunction(value: any): value is Function;
function clone<T>(value: T): T;
function cloneDeep<T>(value: T): T;Mathematical computations including basic arithmetic, aggregation, and range utilities.
function add(augend: number, addend: number): number;
function sum(array: number[]): number;
function max(array: number[]): number | undefined;
function min(array: number[]): number | undefined;
function mean(array: number[]): number;
function range(start?: number, end?: number, step?: number): number[];Deep object operations including property access, merging, transformation, and key/value manipulation.
function get(object: any, path: string | string[], defaultValue?: any): any;
function set(object: any, path: string | string[], value: any): any;
function merge<T, S>(object: T, source: S): T & S;
function omit<T, K extends keyof T>(object: T, ...paths: K[]): Omit<T, K>;
function pick<T, K extends keyof T>(object: T, ...paths: K[]): Pick<T, K>;String transformation utilities for case conversion, templating, and text manipulation.
function camelCase(string?: string): string;
function kebabCase(string?: string): string;
function capitalize(string?: string): string;
function template(string: string, options?: TemplateOptions): TemplateExecutor;
function truncate(string?: string, options?: TruncateOptions): string;
interface TemplateOptions {
escape?: RegExp;
evaluate?: RegExp;
interpolate?: RegExp;
variable?: string;
}
interface TruncateOptions {
length?: number;
omission?: string;
separator?: string | RegExp;
}
type TemplateExecutor = (data?: any) => string;General-purpose utilities including function creation, control flow, and miscellaneous helpers.
function identity<T>(value: T): T;
function noop(): void;
function constant<T>(value: T): () => T;
function times<T>(n: number, iteratee: (index: number) => T): T[];
function uniqueId(prefix?: string): string;Lodash provides powerful chaining capabilities for composing operations:
// Explicit chaining
function chain<T>(value: T): LodashWrapper<T>;
// Chain methods
interface LodashWrapper<T> {
value(): T;
tap(interceptor: (value: T) => void): LodashWrapper<T>;
thru<R>(interceptor: (value: T) => R): LodashWrapper<R>;
}
// Implicit chaining with _(value)
function _<T>(value: T): LodashWrapper<T>;const VERSION: string; // "4.9.0"
interface TemplateSettings {
escape?: RegExp;
evaluate?: RegExp;
interpolate?: RegExp;
variable?: string;
}
const templateSettings: TemplateSettings;type Iteratee<T, R = any> =
| ((value: T, index: number, collection: T[]) => R)
| string
| number
| object;
type Predicate<T> =
| ((value: T, index: number, collection: T[]) => boolean)
| string
| [string, any]
| object;
type PropertyPath = string | number | symbol | Array<string | number | symbol>;
interface LoDashStatic {
VERSION: string;
templateSettings: TemplateSettings;
// All lodash methods are available on the main export
[key: string]: any;
}
interface TemplateSettings {
escape?: RegExp;
evaluate?: RegExp;
interpolate?: RegExp;
variable?: string;
}