Lodash _.pick() Method
Last Updated :
18 Oct, 2023
Lodash _.pick() method is used to return a copy of the object that is composed of the picked object properties. It can be called a subset of the original object as it consists of some of its properties.
Syntax:
_.pick(object, [paths]);
Parameters:
- 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: In this example,
Javascript
const _ = require( "lodash" );
let obj = {
Name: "GeeksforGeeks" ,
password: "gfg@1234" ,
username: "your_geeks"
}
console.log(_.pick(obj, [ 'password' , 'username' ]));
|
Output:
{password: "gfg@1234", username: "your_geeks"}
Example 2:
Javascript
const _ = require( "lodash" );
let obj = { 'x' : 1, 'y' : '2' , 'z' : 3 };
console.log(_.pick(obj, [ 'x' , 'y' ]));
|
Output:
{x: 1, y: '2'}
Share your thoughts in the comments
Please Login to comment...