How to Filter Key of an Object using Lodash? Last Updated : 26 Aug, 2024 Comments Improve Suggest changes 1 Likes Like Report Filtering keys of an object involves selecting specific keys and creating a new object that contains only those keys. Using Lodash, this process allows you to include or exclude properties based on specific criteria, simplifying object manipulation. Below are the approaches to filter keys of an object using Lodash:Table of ContentUsing _.pick() MethodUsing _.omit() MethodUsing _.pick() MethodThis method allows us to create a new object by selecting specific keys from an existing object. It is similar to picking only what we need from the object.Syntax:_.pick(object, [keys])Example: In this example, the original user object has three keys, but the new object filteredUser only includes the name and email keys. JavaScript const _ = require('lodash'); const user = { name: 'Ram', age: 27, email: '[email protected]' }; const filteredUser = _.pick(user, ['name', 'email']); console.log(filteredUser); Output:{ name: 'Ram', email: '[email protected]' }Using _.omit() MethodThe _.omit() method from Lodash is used to generate a new object by excluding specified keys from the original object, providing a way to remove unwanted properties. This method is particularly useful when you want to filter out sensitive or irrelevant data before processing or displaying the object.Syntax:_.omit(object, [keys])Example: This code uses _.omit() to create a new object by excluding the age property from the user object. JavaScript const _ = require('lodash'); const user = { name: 'Shyam', age: 23, email: '[email protected]' }; const filteredUser = _.omit(user, ['age']); console.log(filteredUser); Output:{ name: 'Shyam', email: '[email protected]' } Comment R rekhamiseswt Follow 1 Improve R rekhamiseswt Follow 1 Improve Article Tags : JavaScript Web Technologies JavaScript-Lodash Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)8 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like