How to Convert an Array of Objects into an Array of Arrays ? Last Updated : 03 Jun, 2024 Comments Improve Suggest changes Like Article Like Report An Array of objects is an array that contains multiple objects as its elements which can be converted into an array of arrays i.e. an array that contains multiple arrays as its elements. There are several methods listed below to achieve this task. Table of Content Using Object.keys() and Object.values() methodsUsing Javascript map() methodUsing JavaScript reduce() MethodUsing Object.keys() and Object.values() methodsThe Object.keys() method is used to create an array of object keys while the Object.values() method is used to create an array of values contained by the object. Example: The below example uses the Object.keys() & Object.values() methods to convert an array of objects into an array of arrays. JavaScript let arrOfObj = [ { "Name": "Robert", "Gender": 'M', "Age": 20 }, { "Name": "Aliana", "Gender": 'F', "Age": 34 }, ] const convertToArrofArr = (arrOfObj) => { const valuesArray = []; const keysArray = []; for (let i = 0; i < arrOfObj.length; i++) { let currKey = Object.keys(arrOfObj[i]); let currValue = Object.values(arrOfObj[i]); keysArray.push(currKey); valuesArray.push(currValue); } console.log("Keys Array: ", keysArray); console.log("Values Array: ", valuesArray); } convertToArrofArr(arrOfObj); OutputKeys Array: [ [ 'Name', 'Gender', 'Age' ], [ 'Name', 'Gender', 'Age' ] ] Values Array: [ [ 'Robert', 'M', 20 ], [ 'Aliana', 'F', 34 ] ] Using Javascript map() methodThe map() method allows us to access every key in the array's objects and store them in new array. Similar approach has been followed to access the values of the array of objects which are also stored in the new array. Example : The below code will explain the use of map() method to convert array of objects into array of arrays. JavaScript let arrOfObj = [ { "Name": "Robert", "Gender": 'M', "Age": 20 }, { "Name": "Aliana", "Gender": 'F', "Age": 34 }, ] const convertToArrofArr = (arrOfObj) => { const keysArray = []; const valuesArray = []; arrOfObj.map(obj => { for (let key in obj) { keysArray.push(key); } }); arrOfObj.map(obj => { for (let key in obj) { valuesArray.push(obj[key]); } }); console.log("Keys Array: ", keysArray); console.log("Values Array: ", valuesArray); } convertToArrofArr(arrOfObj); OutputKeys Array: [ 'Name', 'Gender', 'Age', 'Name', 'Gender', 'Age' ] Values Array: [ 'Robert', 'M', 20, 'Aliana', 'F', 34 ] Using JavaScript reduce() MethodThe reduce() method can be used to transform the array of objects into an array of arrays by accumulating the keys and values of each object into separate arrays. Example: The below example uses the reduce() method to convert an array of objects into an array of arrays. JavaScript let arrOfObj = [ { "Name": "Robert", "Gender": 'M', "Age": 20 }, { "Name": "Aliana", "Gender": 'F', "Age": 34 }, ]; const convertToArrofArr = (arrOfObj) => { const result = arrOfObj.reduce((acc, obj) => { acc.keys.push(Object.keys(obj)); acc.values.push(Object.values(obj)); return acc; }, { keys: [], values: [] }); console.log("Keys Array: ", result.keys); console.log("Values Array: ", result.values); } convertToArrofArr(arrOfObj); // Nikunj Sonigara OutputKeys Array: [ [ 'Name', 'Gender', 'Age' ], [ 'Name', 'Gender', 'Age' ] ] Values Array: [ [ 'Robert', 'M', 20 ], [ 'Aliana', 'F', 34 ] ] Comment More infoAdvertise with us Next Article How to Convert an Array of Objects into an Array of Arrays ? riyarjha Follow Improve Article Tags : JavaScript Web Technologies Similar Reads How to Convert an Array of Keys into a Union Type of Objects ? We can convert an array of keys into a union type of objects in typescript using mapped types or object types. The process involves dynamically creating types based on the provided array of keys, resulting in a union type that represents all possible combinations of objects with those keys.Table of 3 min read How to Convert an Array into a Complex Array JavaScript ? Complex arrays can represent multiple dimensions or data with a structure. This article discusses two approaches to converting an array into a more complex array.Table of ContentUsing Multidimensional ArraysUsing Array.from()Using the reduce() MethodUsing the map() Method with slice() MethodUsing Mu 3 min read How to convert Object's array to an array using JavaScript ? Given an array of objects and the task is to convert the object values to an array with the help of JavaScript. There are two approaches that are discussed below: Approach 1:We can use the map() method and return the values of each object which makes the array. Example: html<!DOCTYPE HTML> 2 min read How to Convert an Array of Objects to Map in JavaScript? Here are the different methods to convert an array of objects into a Map in JavaScript1. Using new Map() ConstructorThe Map constructor can directly create a Map from an array of key-value pairs. If each object in the array has a specific key-value structure, you can map it accordingly.JavaScriptcon 3 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 extract value of a property as array from an array of objects ? We will try to understand that how we may extract the value of a property as an array from an array of objects in JavaScript with the help of certain examples.Pre-requisite: Array of Objects in JavaScriptExample:Input:[ { apple: 2, mango: 4, }, { apple: 3, mango: 6, }, { apple: 7, mango: 11, },]Outp 3 min read How to filter an array of objects in ES6 ? In this article, we will try to understand how we could filter out or separate certain data from the array of objects in ES6.Let us first try to understand how we could create an array of objects by following certain syntax provided by JavaScript.Table of ContentJavascript Array of ObjectsJavascript 4 min read How to Convert an Array of Objects into Object in TypeScript ? Converting an array of objects into a single object is a common task in JavaScript and TypeScript programming, especially when you want to restructure data for easier access. In this article, we will see how to convert an array of objects into objects in TypeScript.We are given an array of objects a 3 min read How to Convert an Object into Array of Objects in JavaScript? Here are the different methods to convert an object into an array of objects in JavaScript1. Using Object.values() methodObject.values() method extracts the property values of an object and returns them as an array, converting the original object into an array of objects.JavaScriptconst a = { java: 3 min read How to Convert Array of Objects into Unique Array of Objects in JavaScript ? Arrays of objects are a common data structure in JavaScript, often used to store and manipulate collections of related data. However, there are scenarios where you may need to convert an array of objects into a unique array, removing any duplicate objects based on specific criteria. JavaScript has v 8 min read Like