Lodash Object methods

Beginner
⏱️ 14 min read
📚 Updated: May 2026
🎯 2 Code examples
Lodash

What you’ll learn

  • What to know before you start (see Prerequisites).
  • How the Object group maps to everyday tasks (safe reads, partial shapes, deep merge, iteration).
  • When helpers mutate the destination (assign, merge, set) versus returning new objects (pick, omit, mapValues).
  • How to import Lodash efficiently in modern bundlers.
  • Where to open each _.methodName tutorial on CodeToFun as those pages land.

Prerequisites

Plain objects, property dot/bracket notation, and the difference between own properties and the prototype chain. Optional Number methods when you clamp numeric fields before writing them into objects.

  • Object literals: creating and reading { a: 1, b: { c: 2 } }, including nested paths.
  • Immutability mindset: knowing when your reducer or API layer expects a new reference versus an in-place update.
  • First-class functions: iteratees and customizers used by mapValues, mergeWith, pickBy, and similar APIs.
  • Modules: import with a bundler or require in Node.js so the install snippets match your setup.

Key concepts

Lodash reuses a small vocabulary across the Object category. These four ideas appear in signatures, docs, and TypeScript typings; recognizing them makes every method faster to read.

Path

Many helpers accept a path as a dotted string ("a.b.c"), an array of keys, or a deep path list—see get, set, has, unset.

Iteratee

A function or shorthand that projects values or keys before filtering or mapping—used by mapValues, mapKeys, pickBy, omitBy.

Own vs inherited

forOwn / keys stay on own enumerable string keys; forIn / keysIn also walk the prototype chain.

Destination mutation

assign, merge, set, update, and unset write into an existing object; pick/omit return fresh shells.

Overview

Lodash object helpers cover safe deep reads, whitelisting and blacklisting keys, recursive merging, prototype-aware iteration, and path-based mutation — with one consistent mental model for iteratees and customizers.

Read & probe

get, has, at, and result navigate optional data without long && chains.

Shape & copy

pick, omit, assign, defaults, and merge reshape objects for APIs and state snapshots.

Transform

mapValues, mapKeys, invert, and transform project collections without manual loops.

⚖️ Lodash vs native objects

Modern JavaScript adds Object.assign, spread copies, optional chaining, and structuredClone. Lodash still helps when you need deep paths, recursive merge rules, or iteratee shorthands that would otherwise sprawl.

SituationPrefer nativeConsider Lodash
Shallow copy one level{ ...obj } or Object.assign({}, obj)assign when you already import lodash nearby
Deep optional readOptional chaining obj?.a?.bget with array paths, defaults, or dynamic segments
Recursive mergeHand-rolled recursion or librariesmerge / mergeWith with documented array behavior
Whitelist keys for an API DTODestructuring + literalpick with many keys or path lists
Walk prototype chainfor...in + hasOwnforIn, keysIn, hasIn with consistent semantics
1

Install and import

Install the core package once per project, then import individual functions so bundlers can tree-shake unused helpers.

Terminal
npm install lodash
javascript
import get from "lodash/get";
import pick from "lodash/pick";

const user = { id: 42, name: "Ada", password: "secret" };
const safe = pick(user, ["id", "name"]);
const city = get(user, "address.city", "Unknown");
// safe: { id: 42, name: "Ada" } — password omitted
// city: "Unknown" — missing path uses default

🔄 Mutating vs new objects

Some Lodash object helpers write into the object you pass as the destination. Others return a new object and never touch the source. Mixing them up is a common Redux and React state bug.

StyleTypical methodsRule of thumb
Mutates destinationassign, merge, defaults, set, update, unsetPass a draft object or clone first (cloneDeep) if consumers share the reference.
Returns new datapick, omit, mapValues, mapKeys, invertSafe to return from reducers or memoized selectors without touching the input.

When you control the target (for example const next = {}; merge(next, a, b)), mutating helpers avoid allocating intermediate shells.

Suggested learning path

If you are new to Lodash objects, walk through this order in the REPL or a scratch file. Each step builds on the previous one.

  1. Safe reads: get, has, and at for defensive access.
  2. Shape control: pick / omit before sending data over the wire.
  3. Copies & defaults: assign and defaults for shallow composition.
  4. Deep merge: merge when configs nest objects and arrays.
  5. Path writes: set / update for immutable-style helpers that still mutate the target you choose.

💻 Environment and versions

  • Lodash 4.x: the method list on this page matches the stable 4.x Object exports from lodash@^4 on npm (including entries / entriesIn aliases).
  • Node.js and browsers: same package runs in both; choose ESM imports in bundlers and Vite, or require('lodash/get') in CommonJS projects.
  • TypeScript: install @types/lodash for typings on namespace and per-method imports.

Method index

Each row links to a focused tutorial when it exists on this site. URLs follow the /lodash/object/{method-kebab} pattern (for example /lodash/object/merge-with).

MethodWhat it does
_.assign()Copy own enumerable properties from sources onto the destination object (mutates).
_.assignIn()Like assign, but also copies inherited enumerable string keys from sources.
_.assignInWith()Like assignIn with a customizer for merged values.
_.assignWith()Like assign with a customizer for merged values.
_.at()Collect values at one or more property paths into an array.
_.create()Create a new object linking to the given prototype.
_.defaults()Fill undefined own properties on object from sources (shallow).
_.defaultsDeep()Fill undefined properties recursively from sources.
_.entries()Own enumerable string-keyed entries as pairs (alias of toPairs).
_.entriesIn()Own and inherited string-keyed entries as pairs (alias of toPairsIn).
_.extend()Alias of assignIn (copy including inherited enumerable keys).
_.extendWith()Alias of assignInWith.
_.findKey()First own key whose value satisfies the predicate.
_.findLastKey()Last own key whose value satisfies the predicate.
_.forIn()Invoke iteratee for each own and inherited enumerable string key.
_.forInRight()Like forIn but walks keys right-to-left.
_.forOwn()Invoke iteratee for each own enumerable string key.
_.forOwnRight()Like forOwn but walks keys right-to-left.
_.functions()Return names of own enumerable function properties.
_.functionsIn()Return names of own and inherited enumerable functions.
_.get()Safe deep get with optional default when path is missing.
_.has()Return true if path exists as own property (hasOwnProperty style).
_.hasIn()Return true if path exists anywhere in the prototype chain.
_.invert()Swap keys and values; collisions become arrays of keys.
_.invertBy()Like invert but values grouped by iteratee result.
_.invoke()Call a method at path with arguments on object.
_.keys()Own enumerable string keys of object.
_.keysIn()Own and inherited enumerable string keys.
_.mapKeys()Build a new object with keys mapped by iteratee.
_.mapValues()Build a new object with values mapped by iteratee.
_.merge()Deep merge sources into destination (mutates destination).
_.mergeWith()Like merge with customizer for clashes.
_.omit()Return new object without listed own paths.
_.omitBy()Return new object omitting keys where predicate is truthy.
_.pick()Return new object with only listed own paths.
_.pickBy()Return new object keeping keys where predicate is truthy.
_.result()Resolve path: functions are invoked, missing segments use default.
_.set()Set value at path, creating nested objects as needed (mutates).
_.setWith()Like set with customizer for creating nested containers.
_.toPairs()Own enumerable string-keyed entries as [key, value] pairs.
_.toPairsIn()Own and inherited enumerable string-keyed entries as pairs.
_.transform()Alternative to reduce for building or mutating accumulator object.
_.unset()Delete property at path (mutates).
_.update()Update value at path with updater function (mutates).
_.updateWith()Like update with customizer for creating parents.
_.values()Own enumerable string-keyed values.
_.valuesIn()Own and inherited enumerable string-keyed values.

Pitfalls to avoid

Mutation

Shared references

merge(state, patch) mutates state in place; Redux and React expect new roots when you mean to trigger updates.

Paths

Typos in strings

A wrong dotted path silently returns defaults from get or writes the wrong branch with set; prefer array paths for dynamic segments.

assign vs merge

Depth surprise

assign overwrites nested objects wholesale; merge recursively combines plain objects. Pick the one that matches your payload shape.

❓ FAQ

It groups helpers for copying, merging, walking, projecting, and mutating plain objects (and similar hosts) with path strings or arrays, iteratee shorthands, and consistent own-versus-inherited rules.
Prefer per-method packages (lodash.get) or tree-shakeable ESM imports so your bundle only ships the helpers you call.
Some do: assign and merge write into the destination object; set, update, and unset mutate the target. Others like pick, omit, mapValues, and mapKeys return new objects. Always read the per-method doc before assuming immutability.
Lodash adds deep path support, recursive merge, safe gets with defaults, and iteration helpers that accept iteratee shorthands—patterns that are verbose or easy to get wrong with hand-rolled loops.

Summary

  • Scope: Lodash object helpers complement native static methods with paths, merge depth, and iteratee-driven projections.
  • Bundles: import per method to keep client payloads small.
  • Next step: open Lodash _.assign() or pick any row from the index table above.
Did you know?

Lodash extend and extendWith are aliases of assignIn and assignInWith—the older names for “copy enumerable keys including inherited ones” onto the destination.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

9 people found this page helpful