Lodash _.unset() Method

The 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: This method accepts two parameters as mentioned above and described below:

  • 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:



Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash");  
  
// The source object 
var obj = { 'cpp': [{ 'java': { 'python': 3 } }] };
  
// Use of _.unset() method
console.log(_.unset(obj, 'cpp[0].java.python'));
  
// Object is modified
console.log(obj);

chevron_right


Output:

true
{ cpp: [ { java: {} } ] }

Example 2:  

Javascript

filter_none

edit
close

play_arrow

link
brightness_4
code

// Requiring the lodash library  
const _ = require("lodash");  
  
// The source object 
var obj = { 'cpp': [{ 'java': { 'python': 3 } }] };
  
// Use of _.unset() method
console.log(_.unset(obj, ['html', 'css', 'javascript']));
  
// Object
console.log(obj);

chevron_right


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..

full-stack-img

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.