Lodash _.unset() Method

Beginner
5 min read
Updated: Nov 2026
5 examples
Object

Definition

Removes the property at path of object. Mutates in place. Returns true if the property is deleted, else false. Part of Lodash 4.x Object (since 4.0.0).

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

Syntax

Call _.unset. Start with this line.

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

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

Library declarations
Lodash
_.unset(object, path)

Parameters

ParameterDescription
objectRequired. Target object (mutated)
pathRequired. Dot/bracket string or key array

Return Value

Return ValueDescription
*true / false

Lodash Examples

Example 1 — Official: Nested String Path

Remove a deep property with bracket/dot notation.

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

_.unset(object, "a[0].b.c");
// → true

object;
// → { a: [{ b: {} }] }
Try It Yourself

How It Works

  1. Parse. "a[0].b.c" becomes path segments.
  2. Walk. Reach the parent object { c: 7 }.
  3. Delete. Remove c in place.
  4. Parents. b remains as an empty object.

Example 2 — Official: Array Path

Same deletion using a key array instead of a string.

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

_.unset(object, ["a", "0", "b", "c"]);
// → true

object;
// → { a: [{ b: {} }] }
Try It Yourself

How It Works

  1. Array path. Each element is one segment.
  2. Index. "0" selects the first array item.
  3. Same result. Equivalent to the string path form.
  4. Prefer. Arrays when keys contain dots.

Example 3 — Missing Path → false

Unresolved parents return false without throwing.

Lodash
var object = { a: 1 };

_.unset(object, "x.y.z");
// → false

object;
// → { a: 1 }
Try It Yourself

How It Works

  1. Walk. x does not exist on the object.
  2. Fail. Parent cannot be resolved.
  3. Return. false — object unchanged.
  4. Safe. No exception for bad paths.

Example 4 — Top-Level Key

Works for shallow keys too — like a safe delete.

Lodash
var user = { id: 1, temp: true, name: "Ada" };

_.unset(user, "temp");
// → true

user;
// → { id: 1, name: "Ada" }
Try It Yourself

How It Works

  1. Path. Single segment "temp".
  2. Delete. Removes the own property.
  3. Keep. Other keys stay intact.
  4. Use. Strip temporary or sensitive fields.

Example 5 — unset vs omit

Mutate nested paths vs return a new object without top-level keys.

Lodash
var data = { user: { id: 1, secret: "x" }, ok: true };

_.unset(data, "user.secret");
// data is mutated → { user: { id: 1 }, ok: true }

_.omit({ a: 1, b: 2 }, ["b"]);
// → { a: 1 }  (new object; source unchanged)
Try It Yourself

How It Works

  1. unset. Nested path + in-place delete.
  2. omit. Top-level keys + new object.
  3. Pick. Deep cleanup → unset. Shallow copy → omit.
  4. Immutable unset. Combine with _.cloneDeep first.

Browser & Runtime Support

_.unset is a Lodash Object helper (since 4.0.0). It runs anywhere Lodash runs — modern browsers (CDN or bundle) and Node.js / Bun / Deno with npm install lodash. Closest native cousin is walking a path then using the delete operator; Lodash adds safe path parsing (dot/bracket/array) and a boolean result without throwing on missing parents.

✓ Stable · Lodash 4.x

_.unset()

Available in [email protected] full builds and the lodash/unset 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
_.unset Lodash 4.x+

Bottom line: Safe for production once Lodash is loaded. Prefer import unset from "lodash/unset" for smaller builds. Ideal for stripping nested secrets, temp flags, or draft fields.

Frequently Asked Questions

_.unset(object, path) removes the property at path. It mutates object in place and returns true if the property was removed (or was already absent after resolving the parent), otherwise false when the path cannot be resolved.
Yes. Like _.set, it changes the object you pass. Clone first if you need immutability: _.unset(_.cloneDeep(obj), path).
Same as _.get / _.set: 'a[0].b.c', 'a.0.b.c', or ['a', '0', 'b', 'c'].
Returns false and leaves the object unchanged. No throw.
omit returns a new object and removes top-level keys by name. unset deletes any nested path and mutates in place.
Use import unset from "lodash/unset" or require("lodash/unset"). Full build: import _ from "lodash" then _.unset.

Next: _.update()

Transform a nested value with an updater function.

_.update() 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