How to use pickBy function In Lodash
In this approach, we are using the pickBy function from Lodash with an object and a predicate function, creating a new object res that includes keys based on the condition specified in the predicate, which excludes the key ‘b’ from the original object obj.
Syntax:
_.pickBy(object, [predicate=_.identity])
Example: The below example uses the pickBy function to filter the keys of an object with lodash.
const _ = require('lodash');
let obj = { a: 1, b: 2, c: 3 };
let res = _.pickBy(obj, (value, key)
=> key !== 'b');
console.log(res);
Output:
{ a: 1, c: 3 }
How to Filter Keys of an Object with Lodash ?
Filtering Keys of an Object is used for selectively including or excluding keys based on criteria, facilitating data manipulation and customization.
Below are the approaches to filter keys of an object with Lodash:
Table of Content
- Using pick function
- Using omit function
- Using pickBy function
Installing the Lodash library using the below command:
npm i lodash
Contact Us