How convert object list into map?

Victor1125

I want to convert array of objects with fields name and value into map and I have no idea how to do this. I get:

[
    {"name": "key1", "value": "value1"},
    {"name": "key2", "value": "value2"},
    {"name": "key3", "value": "value3"}
]

But I need to send in request:

[
    {"key1": "value1"},
    {"key2": "value2"},
    {"key3": "value3"}
]
Elias Soares

Just use Array.map:

const output = input.map(
  (row) => ({[row.name]: row.value})
);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to convert Map to List of User Object?

How to convert List of Objects to map using object's fields in Java

How to convert a Map to List in Java?

Java: How to convert List to Map

How to Convert List<Map<String, Object>> to List<Map<String, String>>

How to convert with Java stream List<Map<String,Object>> to List<String> removing part of each Stream

How to Convert a List Into Map of Map Map<String, Map<String,Object>>

How to convert Class object to data structure `Map` or a `List of Maps` in Dart?

Convert List<Map<String, Object>> to String[][]

How to convert List to Map in Kotlin?

How to convert List of Objects into Map<Object, Object> using Java 8 Lambdas

Convert List of Object to Map with duplicate key

Convert list of Object to Map<Key, List<Object>> with java 8 stream

How can i convert Map of Strings and Object to a Map of Strings and List

How to convert Map to array of object?

How to convert a nested list of objects into a map (Map<Integer, Map<Integer, Object>>) using lambdas/streams

How to convert Object list into a map of <String, List<String>>?

How to map data from Firestore to a list and convert to object data type

Convert Map<String, Object> to Map<String, List<Object>>

How to convert the following map/list?

Convert byte[] to List<Map<String, Object>>

How to build a Map<Object, List<Object>> map from a List<Object>

How to convert Future<List<Object>> to List<Object>?

How to convert List<Map<String,Object>> to Map<String, String>?

How to efficiently convert a list into a map?

How to convert list to Map of Map

Unable to convert map to list of object : dart

How do I convert a Map in LIst to a Map?

how to convert a List of objects to map