Using _.pick() function from lodash
In this lab, you'll be working with the _pick() function in lodash. Lodash is a popular JavaScript utility library that provides helpful functions for common programming tasks. The _.pick() function creates an object by picking properties from another object based on the keys provided.
You will be creating a function called filteredObject
that takes two arguments: an object inputObj
and an array of strings keyArrayList
. The goal is to use lodash's _.pick() inside filteredObject
to create and return a new object with only the properties specified in keyArrayList
from inputObj
.
Challenges
- Import the
lodash
package and assign it to a variable named_
. - Create and export a function called
filteredObject
that accepts two arguments:inputObj
andkeyArrayList
. - The
filteredObject
function should use lodash's_.pick()
function to pick the properties frominputObj
specified inkeyArrayList
and return the new object. - Make sure the
filteredObject
function works with various input examples.
Note: You will need to install the lodash package (npm install lodash
) and import it in your solution. Don't forget to include lodash
as a dependency in your package.json
file in the solution.