how to use the valuesin function from lodash in javascript

The _.valuesIn function from lodash is a utility function used to retrieve all enumerable property values from an object. Here is an example:

index.tsx
const _ = require('lodash');

const person = {
  firstName: 'John',
  lastName: 'Doe',
  age: 30,
  city: 'New York'
};

const values = _.valuesIn(person);

console.log(values); // Outputs: [ 'John', 'Doe', 30, 'New York' ]
224 chars
13 lines

In this example, we import the lodash library using the require statement. We then define an object called person with four properties. We then use the _.valuesIn function to retrieve all property values from the person object and store them in the values variable. Finally, we output the values array to the console.

Note that the _.valuesIn function retrieves not only the values of the properties that are directly on the object, but also the values of any inherited properties from its prototype chain. This is different from the _.values function, which only retrieves the values of the object's own properties.

gistlibby LogSnag