Lodash _.unset() Method
Last Updated :
25 Oct, 2023
Lodash _.unset() method is used to remove the property at the path of the object. If the property is removed then it returns True value otherwise, it returns False.
Syntax:
_.unset(object, path);
Parameters:
- object: This parameter holds the object to modify.
- path: This parameter holds the path of the property to unset. It can be an array or string.
Return Value:
This method returns true if the property is deleted, else false.
Example 1: In this example, we are removing the path by passing them into the _.unset() method.
Javascript
const _ = require( "lodash" );
let obj = { 'cpp' : [{ 'java' : { 'python' : 3 } }] };
console.log(_.unset(obj, 'cpp[0].java.python' ));
console.log(obj);
|
Output:
true
{ cpp: [ { java: {} } ] }
Example 2: In this example, we are removing the path by passing them into the _.unset() method.
Javascript
const _ = require( "lodash" );
let obj = { 'cpp' : [{ 'java' : { 'python' : 3 } }] };
console.log(_.unset(obj, [ 'html' , 'css' , 'javascript' ]));
console.log(obj);
|
Output:
true
{ cpp: [ { java: [Object] } ] }
Note: This will not work in normal JavaScript because it requires the library lodash to be installed and can be installed using npm install lodash..
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...