transform list of object into object

kn3l

I have input list of object,

[
{"id":1,"name":"USD - US Dollar","country":"US","created_at":"2018-05-28 
14:54:24","updated_at":"2018-05-28 14:54:24"},
{"id":2,"name":"TH- Thai Bat","country":"TH","created_at":"2018-05-28 
14:54:24","updated_at":"2018-05-28 14:54:24"}
] 

I want to transform into , anyone please guide me.

{"US": "USD - US Dollar","TH": "TH- Thai Bat"}
CertainPerformance

Use reduce to turn an array into a single object:

const input = [
{"id":1,"name":"USD - US Dollar","country":"US","created_at":"2018-05-28 14:54:24","updated_at":"2018-05-28 14:54:24"},
{"id":2,"name":"TH- Thai Bat","country":"TH","created_at":"2018-05-28 14:54:24","updated_at":"2018-05-28 14:54:24"}
];

const output = input.reduce((a, { name, country }) => {
  a[country] = name;
  return a;
}, {});
console.log(output);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Transform List of object to a Map in java

Accessing transform of a game object in a list

Java Transform Json to List<Object>

Java8 Transform list of object to list of one attribute of object

Transform a list of object to lists of its field

Javascript transform list of objects into object with key value

Correct way to transform Object from Firebase list?

Kotlin: transform a list of objects into a map of object properties

Transform an object (map) into a distinct list with terraform

Transform an array of objects in an object list with a property of the object as key

In R, how do I transform a complex list object into a dataframe object

Transform an object to a list[object] in Realm as migration ( How can i replace a list[objects] with object field in Realm? )

Using RxJava to fetch object, transform a containing list, and use the list

Java 8 - How to transform a List of arrays into a List of a specific class object

Iterate through list of objects and transform into an object with nested list of objects

Transform InputStream into Object, then Object into Json

Transform values inside object of object

Transform list of objects from response to differnt object Angular 6

How to transform list of objects into object of lists using jq?

How to transform a list of character vectors into a quanteda tokens object?

Java how to transform List<Object> to Page from JPA Paggination

How to transform a list of one object to another in rx Java

How to transform a list of dataframes into one single zoo object R

How to transform a list of objects into an outer new object of objects?

Projection of containers, i.e. method to transform List<Object> to List<Object.Member>

How to transform a List<Map<String, Object>> into Map<String, List<Object>> using Java 8

how to filter and transform a List<Map<String,object>> in to new List<Map<String,object>> with different key value

Transform object in js

Javascript object transform