Lodash _.update() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

This method is like _.set except that it accepts an updater to produce the value to set. Mutates object and returns it. Part of Lodash 4.x Object (since 4.6.0).

Pass the object and path or keys shown below. Check whether the helper mutates or returns a new object.

Syntax

Call _.update. Start with this line.

Lodash
_.update(object, path, updater)
CallWhat it does
_.update(object, path, updater)Primary signature.
_.update(object)Work with an object’s keys, values, or paths.

Prefer import update from "lodash/update" when you want a smaller bundle.

Library declarations
Lodash
_.update(object, path, updater)

Parameters

ParameterDescription
objectRequired. Target object (mutated)
pathRequired. Dot/bracket string or key array
updaterRequired. (value) => newValue

Return Value

Return ValueDescription
*The same object reference

Lodash Examples

Example 1 — Official: Square Nested Value

Read c, square it, write it back.

Lodash
var object = { a: [{ b: { c: 3 } }] };

_.update(object, "a[0].b.c", function (n) {
  return n * n;
});

object.a[0].b.c;
// → 9
Try It Yourself

How It Works

  1. Get. Current value at the path is 3.
  2. Update. Updater returns 9.
  3. Set. Lodash writes 9 back at the path.
  4. Docs. Matches the official Lodash example.

Example 2 — Official: Missing Path → undefined

Updater must handle a missing value; intermediates are created.

Lodash
var object = { a: [{ b: { c: 3 } }] };

_.update(object, "x[0].y.z", function (n) {
  return n ? n + 1 : 0;
});

object.x[0].y.z;
// → 0
Try It Yourself

How It Works

  1. Missing. Path does not exist yet → n is undefined.
  2. Fallback. Updater returns 0.
  3. Create. Lodash builds x[0].y containers.
  4. Write. Sets z to 0.

Example 3 — Toggle a Nested Boolean

Classic updater: flip true/false.

Lodash
var settings = { ui: { dark: false } };

_.update(settings, "ui.dark", function (on) {
  return !on;
});

settings.ui.dark;
// → true
Try It Yourself

How It Works

  1. Read. Current flag is false.
  2. Flip. !on → true.
  3. Write. Path updated in place.
  4. Why update. You did not need to call get then set yourself.

Example 4 — Increment a Counter

Add one to a nested score using an array path.

Lodash
var game = { players: [{ score: 10 }] };

_.update(game, ["players", "0", "score"], function (n) {
  return n + 1;
});

game.players[0].score;
// → 11
Try It Yourself

How It Works

  1. Array path. Segments select players[0].score.
  2. Current. Score is 10.
  3. Next. Updater returns 11.
  4. Result. Counter advances without a separate get.

Example 5 — update vs set

Use set when you already know the value; update when you derive it.

Lodash
var a = { n: 2 };
var b = { n: 2 };

_.set(a, "n", 5);
// a.n → 5  (you supplied 5)

_.update(b, "n", function (n) {
  return n * 2;
});
// b.n → 4  (derived from 2)
Try It Yourself

How It Works

  1. set. Writes a finished value.
  2. update. Computes from the current value.
  3. Same mutate. Both change the object in place.
  4. Pick. Known value → set. Derived value → update.

Browser & Runtime Support

_.update is a Lodash Object helper (since 4.6.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Closest pattern is _.set(obj, path, updater(_.get(obj, path))); Lodash packages that into one call with shared path parsing.

✓ Stable · Lodash 4.x

_.update()

Available in [email protected] full builds and the lodash/update modular import. Works in evergreen browsers and current Node LTS when Lodash is installed.

100% With Lodash 4.x
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
_.update Lodash 4.6+

Bottom line: Safe for production once Lodash is loaded. Prefer import update from "lodash/update" for smaller builds. Ideal for toggles, counters, and derived nested writes.

Frequently Asked Questions

_.update(object, path, updater) reads the value at path, passes it to updater, and writes the return value back. Mutates object and returns it.
set assigns a finished value. update computes the new value from the current one — toggles, increments, string transforms.
The updater receives undefined. Lodash still creates intermediate containers when writing the result (like set).
Yes. Clone first when you need immutability: _.update(_.cloneDeep(obj), path, fn).
When you need a customizer to control how missing intermediate objects/arrays are created along the path.
Use import update from "lodash/update" or require("lodash/update"). Full build: import _ from "lodash" then _.update.

Next: _.updateWith()

Transform a nested value and customize intermediate containers.

_.updateWith() tutorial →

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.

10 people found this page helpful