Friday, September 5, 2025
HomeLanguagesJavascriptLodash _.pick() Method

Lodash _.pick() Method

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




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


Output:

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

Example 2:  

Javascript




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


Output:

{x: 1, y: '2'}
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6638 POSTS0 COMMENTS
Nicole Veronica
11802 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11866 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7027 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS