# Lodash — Modular Utility Library for JavaScript > Lodash is the most-downloaded utility library on npm. Modular helpers for arrays, objects, strings, collections, and functions — clone, debounce, throttle, merge, groupBy, and hundreds more battle-tested functions. ## Install Save in your project root: ## Quick Use ```bash npm i lodash # Or modular npm i lodash.debounce lodash.throttle lodash.clonedeep ``` ```ts import _ from "lodash"; // Debounce expensive function const search = _.debounce((q: string) => { fetch(`/api/search?q=${q}`); }, 300); // Deep clone const copy = _.cloneDeep(original); // Group and aggregate const users = [{ age: 25, role: "dev" }, { age: 30, role: "dev" }, { age: 28, role: "pm" }]; const byRole = _.groupBy(users, "role"); const avgAge = _.meanBy(users, "age"); // 27.67 // Functional pipeline const result = _.chain(users) .filter({ role: "dev" }) .sortBy("age") .map("age") .value(); // [25, 30] ``` ## Intro Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. Created by John-David Dalton as a fork of Underscore.js focused on performance. 200+ utility functions covering arrays, objects, strings, collections, numbers, dates, functions, and more. - **Repo**: https://github.com/lodash/lodash - **Stars**: 61K+ - **Weekly downloads**: 70M+ - **License**: MIT ## What Lodash Does - **Array** — chunk, difference, flatten, uniq, zip - **Collection** — each, filter, groupBy, map, reduce, sortBy - **Function** — debounce, throttle, memoize, once, partial - **Lang** — clone, cloneDeep, isEqual, isEmpty, merge - **Object** — get, set, pick, omit, invert, mapKeys - **String** — camelCase, kebabCase, startCase, template, truncate - **Chain** — fluent API for composing operations - **FP** — `lodash/fp` provides auto-curried, immutable versions ## Architecture Highly optimized pure-JS functions, many with custom fast paths for common cases. Each function is publishable as its own npm package (`lodash.debounce`) for minimal bundles. The main `lodash` package is ~70KB gzipped but heavily tree-shakeable. ## Self-Hosting Client library — ships in bundle. ## Key Features - 200+ utility functions - Tree-shakeable when imported by name - Separate tiny packages per function - Functional programming variant (`lodash/fp`) - Chaining API - TypeScript types (`@types/lodash`) - Battle-tested (30M+ projects use it) - Zero runtime dependencies ## Comparison | Library | Size | Features | Immutable | TS | |---|---|---|---|---| | Lodash | ~70KB | 200+ | fp variant | via @types | | Ramda | ~50KB | 200+ (FP only) | Yes | Yes | | Radash | ~10KB | 100+ | Yes | Native | | es-toolkit | ~8KB | 100+ | Yes | Native | | Underscore | ~15KB | 100+ | No | via @types | ## 常见问题 FAQ **Q: ES2023 了还需要 Lodash?** A: 大部分简单操作可以用原生(Array.flat, Object.fromEntries),但 cloneDeep, debounce, isEqual, groupBy 原生还不够好或不存在。 **Q: Bundle 太大?** A: 按函数导入 `import debounce from "lodash/debounce"`,或用 `lodash-es` + tree-shake。 **Q: 有更现代的替代吗?** A: 有。es-toolkit(TypeScript 原生、零依赖、更小)和 Radash 是新势力。 ## 来源与致谢 Sources - Docs: https://lodash.com/docs - GitHub: https://github.com/lodash/lodash - License: MIT --- Source: https://tokrepo.com/en/workflows/70e5a808-35a3-11f1-9bc6-00163e2b0d79 Author: AI Open Source