I am trying to create an object using the values of items inside an array.
const arrOfObj = [
{city: 'Tokyo', country: 'Japan', ...other values},
{city: 'Paris', country: 'France', ...other values},
{city: 'London', country: 'UK', ...other values},
{city: 'New York', country: 'USA', ...other values}
]
expected object:
const obj = {
Japan: 'Tokyo',
France: 'Paris',
UK: 'London',
USA: 'New York'
}
Can you guys have any suggestion to achieve this in an efficient way? All the comments will be highly appreciated. Thank you.