Skip to content
Related Articles

Related Articles

Save Article
Improve Article
Save Article
Like Article

Lodash _.pickBy() Method

  • Last Updated : 09 Sep, 2020

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

The _.pickBy() method is used to return a copy of the object that composed of the object properties predicate returns truthy for.

Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!

Syntax:

_.pickBy( object, predicate )

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



  • object: This parameter holds the source object.
  • predicate: This parameter holds the function that is invoked for every property. It is an optional value.

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: 123456, 
    username: "your_geeks"
}
  
// Using the _.pickBy() method 
console.log(_.pickBy(obj, _.isLength));

Output:

{'password': 123456}

Example 2:  

Javascript




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

Output:

{'x': 1, 'z': 3}
My Personal Notes arrow_drop_up
Recommended Articles
Page :