How to Convert Object to Array in Lodash ? Last Updated : 29 Apr, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report 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 functionRun the below command before running the below code on your system: npm i lodashUsing toArray function In this approach, we are using Lodash's toArray function, which converts the values of an object into an array, resulting in an array representation of the object's properties, useful for array operations and transformations. Syntax:_.toArray(value)Example: The below example uses the toArray function to convert the object to an array in lodash. JavaScript const _ = require('lodash'); let obj = { a: 1, b: 2, c: 3 }; let arr = _.toArray(obj); console.log(arr); Output: [ 1, 2, 3 ]Using values functionIn 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. JavaScript const _ = require('lodash'); let obj = { a: 1, b: 2, c: 3 }; let arr = _.values(obj); console.log(arr); Output: [ 1, 2, 3 ] Comment More infoAdvertise with us Next Article How to Convert Object Array to Hash Map using Lodash ? G gauravgandal Follow Improve Article Tags : JavaScript Web Technologies JavaScript-Lodash Similar Reads How to Convert Object to Array in JavaScript? In this article, we will learn how to convert an Object to an Array in JavaScript. Given an object, the task is to convert an object to an Array in JavaScript. Objects and Arrays are two fundamental data structures. Sometimes, it's necessary to convert an object to an array for various reasons, such 4 min read How to Convert Object Array to Hash Map using Lodash ? Converting an Object Array to a Hash Map consists of manipulating the array elements to create a key-value mapping. Below are the different approaches to Converting an object array to a hash map using Lodash:Table of Content Using keyBy() functionUsing reduce functionRun the below command before run 2 min read How to convert a map to array of objects in JavaScript? A map in JavaScript is a set of unique key and value pairs that can hold multiple values with only a single occurrence. Sometimes, you may be required to convert a map into an array of objects that contains the key-value pairs of the map as the values of the object keys. Let us discuss some methods 6 min read How to Convert String of Objects to Array in JavaScript ? This article will show you how to convert a string of objects to an array in JavaScript. You have a string representing objects, and you need to convert it into an actual array of objects for further processing. This is a common scenario when dealing with JSON data received from a server or stored i 3 min read How to Convert String to Array of Objects JavaScript ? Given a string, the task is to convert the given string to an array of objects using JavaScript. It is a common task, especially when working with JSON data received from a server or API. Below are the methods that allow us to convert string to an array of objects:Table of ContentUsing JSON.parse() 4 min read How to Replace Objects in Array using Lodash? Replacing objects in an array using Lodash typically involves identifying the specific object(s) you want to replace and then performing the replacement operation. Lodash provides a range of methods to facilitate such operations, although the actual replacement might involve combining Lodash functio 3 min read Like