VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-pickby-method/

⇱ Lodash _.pickBy() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.pickBy() Method

Last Updated : 18 Oct, 2023

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:

  • object(Object) parameter holds the source object.
  • predicate(function) 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: In this example, we are using the _pickBy() method in which we are passing the _.isLength() method.

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.

Output:

{'x': 1, 'z': 3}
Comment