Open In App

Lodash _.pickBy() Method

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

Syntax:

_.pickBy( object, [predicate] )

Parameters:

Return Value:

This method returns the new object.



Example 1: In this example, we are using the _pickBy() method in which we are passing the _.isLength() method.




// Requiring the lodash library 
const _ = require("lodash");
 
// The source object
let obj = {
    Name: "GeeksforGeeks",
    password: 123456,
    username: "your_geeks"
}
 
// Using the _.pickBy() method
console.log(_.pickBy(obj, _.isLength));

Output:



{'password': 123456}

Example 2: In this example, we are using the _pickBy() method in which we are passing the _.isNumber() method which returns true if the value is a number.




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

Output:

{'x': 1, 'z': 3}
Article Tags :