Lodash Cheatsheet - Utility Functions

This reference is for JS devs who would rather use a well-tested helper than reimplement the same loop by hand. Entries span arrays, objects, strings, collections, and function utilities, with each command showing the exact call that solves a stubborn problem — like reading a deeply nested value that may not exist, deep-cloning to avoid mutating shared state, or debouncing an input handler. Unlike native methods, Lodash versions handle nullish inputs and edge cases for you. After reading you should be able to pick the right helper for dedupe, grouping, debounce, and safe deep merge.

Languages·44 commands·Last updated 2026-07-21
lodashjavascriptUtility LibrariesFrontend

Array 7

_.map(arr, (n) => n * 2)
Map to a new array
_.filter(arr, (n) => n > 0)
Filter matching elements
_.reduce(arr, (sum, n) => sum + n, 0)
Reduce / accumulate
_.chunk(arr, 2)
Chunk into groups of 2
_.flattenDeep([1, [2, [3]]])
Deep flatten
_.uniq([1, 2, 1, 3])
Deduplicate an array
_.union([1, 2], [2, 3])
Union multiple arrays (deduped)

Object 7

_.get(obj, "a.b.c", "default")
Safely get a nested property
_.set(obj, "a.b.c", value)
Safely set a nested property
_.pick(obj, ["name", "age"])
Pick specified properties
_.omit(obj, ["password"])
Omit specified properties
_.merge(target, source)
Deep-merge objects
_.cloneDeep(obj)
Deep clone
_.keys(obj) / _.values(obj)
Get keys / values arrays

String 6

_.camelCase("Foo Bar")
Convert to camelCase
_.kebabCase("FooBar")
Convert to kebab-case
_.template("<%= name %>")({ name: "Vue" })
Compile a template string
_.escape("<a>")
HTML escape
_.trim(" abc ")
Trim whitespace
_.pad("abc", 8)
Pad to a length

Collection 6

_.groupBy(users, "age")
Group by a property
_.sortBy(users, ["age", "name"])
Sort by multiple properties
_.countBy([1, 2, 2, 3], Math.floor)
Count by a rule
_.keyBy(users, "id")
Key an array by a property
_.sampleSize(arr, 2)
Sample n random elements
_.shuffle(arr)
Shuffle

Function 6

_.debounce(fn, 300)
Debounce (runs after idle)
_.throttle(fn, 300)
Throttle (fixed rate)
_.memoize(fn)
Memoize results
_.once(fn)
Run once
_.partial(fn, _, 2)
Partial application
_.bind(fn, thisArg, arg1)
Bind this and args

Number & Math 5

_.random(0, 100)
Random integer 0-100
_.range(0, 5)
Range [0, 1, 2, 3, 4]
_.clamp(num, 0, 100)
Clamp to a range
_.inRange(num, 0, 100)
Check if in range
_.round(1.234, 2)
Round to 2 decimals

Utility & Type 7

_.isEmpty(value)
Check if empty
_.isEqual(a, b)
Deep equality
_.isNil(value)
Check null or undefined
_.isArray(value) / _.isObject(value)
Type checks (array/object)
_.has(obj, "a.b")
Check a property path exists
_.defaults({ a: 1 }, { a: 0, b: 2 })
Fill in undefined properties
_.noop()
No-op placeholder

Tips

  • lodash-es is the ESM build with tree-shaking for smaller bundles.
  • _.get/_.set safely handle deeply nested objects without undefined errors.
  • Use debounce for search inputs, throttle for scroll/resize.
  • Modern JS can replace some Lodash with natives like flat() and Object.keys().
  • Import a single method (e.g. lodash/cloneDeep) to shrink the bundle further.

Official References

Each command links to its official documentation below, so you can verify the latest usage and read deeper.

Maintained by LaoHand

Publicly updated on Jul 21, 2026, continuously proofread against official docs.

Contact Us

Wrong command or description? Send us corrections, business inquiries or product feedback by email.

Contact Us