The lodash method _.unset exported as a module for removing object properties at specified paths.
npx @tessl/cli install tessl/npm-lodash--unset@4.5.0The lodash method _.unset exported as a standalone Node.js module for removing object properties at specified paths. This package provides a focused, dependency-free way to safely remove nested properties from objects using flexible path notation.
npm install lodash.unsetvar unset = require('lodash.unset');Note: This package is built for CommonJS and does not provide native ES6 module exports.
var unset = require('lodash.unset');
// Create a test object
var object = { 'a': [{ 'b': { 'c': 7 } }] };
// Remove nested property using dot notation
var result = unset(object, 'a[0].b.c');
console.log(result); // => true
console.log(object); // => { 'a': [{ 'b': {} }] }
// Remove property using array path
var object2 = { 'a': [{ 'b': { 'c': 7 } }] };
var result2 = unset(object2, ['a', '0', 'b', 'c']);
console.log(result2); // => true
console.log(object2); // => { 'a': [{ 'b': {} }] }Removes the property at the specified path of an object. The method mutates the original object and supports various path formats.
/**
* Removes the property at `path` of `object`.
*
* Note: This method mutates `object`.
*
* @param {Object} object The object to modify.
* @param {Array|string} path The path of the property to unset.
* @returns {boolean} Returns `true` if the property is deleted, else `false`.
*/
function unset(object, path);Parameters:
object (Object): The object to modify. Can be null or undefined (treated as no-op).path (Array|string): The path of the property to unset. Supports multiple formats:
'a.b.c''a[0].b.c', 'a["key"].b''a[0].b["key"].c'['a', 0, 'b', 'key', 'c']Returns:
boolean: Returns true if the property is deleted, false if the property doesn't exist or deletion fails.Behavior:
true for null or undefined objects (no-op).false for paths that don't exist.Usage Examples:
var unset = require('lodash.unset');
// Dot notation
var obj1 = { a: { b: { c: 42 } } };
unset(obj1, 'a.b.c');
// => true, obj1 is now { a: { b: {} } }
// Bracket notation with array indices
var obj2 = { users: [{ name: 'Alice', age: 30 }] };
unset(obj2, 'users[0].age');
// => true, obj2 is now { users: [{ name: 'Alice' }] }
// Array path format
var obj3 = { data: { items: [{ id: 1, value: 'test' }] } };
unset(obj3, ['data', 'items', 0, 'value']);
// => true, obj3 is now { data: { items: [{ id: 1 }] } }
// Mixed notation with quoted keys
var obj4 = { 'special-key': { 'another key': 'value' } };
unset(obj4, '["special-key"]["another key"]');
// => true, obj4 is now { 'special-key': {} }
// Handle non-existent paths gracefully
var obj5 = { a: 1 };
unset(obj5, 'b.c.d');
// => false, obj5 remains { a: 1 }
// Handle null/undefined objects
unset(null, 'any.path');
// => true (no-op)
unset(undefined, 'any.path');
// => true (no-op)The unset function supports sophisticated path parsing:
'property.nested.deep''property["key"]', 'property[0]''property[0].nested["key"]'['property', 0, 'nested', 'key']'key["with \"quotes\""]')falsefalse for non-configurable properties