Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Lodash _.pick() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.pick() method is used to return a copy of the object that is composed of the picked object properties.

Syntax:

_.pick( object, paths )

Parameters: This method accepts two parameters as mentioned above and described below:

  • object: This parameter holds the source object.
  • paths: This parameter holds the property paths to pick.

Return Value: This method returns the new object.

Example 1:

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// The source object
var obj = { 
    Name: "GeeksforGeeks"
    password: "gfg@1234"
    username: "your_geeks"
}
  
// Using the _.pick() method 
console.log(_.pick(obj, ['password', 'username']));


Output:

{password: "gfg@1234", username: "your_geeks"}

Example 2:  

Javascript




// Requiring the lodash library  
const _ = require("lodash");  
  
// The source object
var obj = { 'x': 1, 'y': '2', 'z': 3 };
  
// Using the _.pick() method 
console.log(_.pick(obj, ['x', 'y']));


Output:

{x: 1, y: '2'}
My Personal Notes arrow_drop_up
Last Updated : 07 Sep, 2020
Like Article
Save Article
Similar Reads
Related Tutorials