How do I convert an object array to an object list

Kimaya :

I have the following structure :

[
   {
     "key": "Asset Type",
     "values": ["Appliances", "Electronics"]
    }, 
    {
      "key": "Asset Availability",
      "values": ["In Stock"]
    }
]

I need to convert it to :

{
  "Asset Type": ["appliances", "electronics"],
  "Asset Availability": ["in stock"]
}

How can I do that?

Tibebes. M :

Here is one approach using Object.fromEntries and Array.prototype.map (to transform the array into 2d-array since that's what the Object.fromEntries expect)

const items = [{
    "key": "Asset Type",
    "values": ["Appliances", "Electronics"]
  },
  {
    "key": "Asset Availability",
    "values": ["In Stock"]
  }
]

console.log(
  Object.fromEntries(items.map(({
    key,
    values
  }) => [key, values]))
)

Collected from the Internet

Please contact javaer1[email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do i convert a json array object of an object into a java 8 optional list of that object

How do I convert array of Objects into one Object in JavaScript?

How do I convert a javascript object array to a string array of the object attribute I want?

How do I convert an array of objects into an object (dynamically) in JavaScript

How do I convert an array object to a string in PowerShell?

How do I convert an object to an array?

How do I convert array of objects to object in javascript?

How do I convert an array of strings to an object property in javascript?

how do I convert an object to an array list in JS

How do you convert a List of object to a one dimensional array?

How do i convert an array with varying size to a JSON object?

How do i convert List into datetime.date object?

How do I convert a Json file (that contains a array) to a List (of a class object) C# Unity

How do I convert array of Objects to one Object in JavaScript?

How do i convert "[object Object]" to a number

how do i convert json object to array without key

How do i convert my values in an array/object to measure them?

How do I convert string array values to object in c#

How do I convert an Array with a JSON string into a JSON object (ruby)

How do I convert List<List<Object>> to a multi-dimensional array?

How do I use GSON to convert an object array to an array of their IDs

How do I convert an array into an object within array - Angular and Javascript

How do I convert Pandas object to a list in python3

How can I convert this list of pairs into an object that contains an array of arrays?

Error 'int' object is not subscriptable, How do i convert it to list?

How do I convert an array object into a two-dimensional array

How do I convert a list into a dictionary grouped by object name?

How do i convert JSON object to an array as above?

How do i convert an array of objects into 1 object in typescript