How to use values function In Lodash
In this approach, we are using Lodash’s values function to extract the values of an object and convert them into an array, providing an array representation of the object’s properties for easier array-based operations.
Syntax:
_.values(object)
Example: The below example uses the values function to convert the object to an array in lodash.
const _ = require('lodash');
let obj = { a: 1, b: 2, c: 3 };
let arr = _.values(obj);
console.log(arr);
Output:
[ 1, 2, 3 ]
How to Convert Object to Array in Lodash ?
Converting an Object to an Array consists of changing the data structure from key-value pairs to an array format.
Below are the different approaches to converting objects to arrays in Lodash:
Table of Content
- Using toArray function
- Using values function
Run the below command before running the below code on your system:
npm i lodash
Contact Us